tsk-268: Extend get cover art (#269)
soaricarus_api CI / Check (push) Successful in 4m59s
soaricarus_api CI / Rustfmt (push) Successful in 2m26s
soaricarus_api CI / Clippy (push) Successful in 4m18s
soaricarus_api CI / build (push) Successful in 5m1s
soaricarus_api CI / Test Suite (push) Failing after 2m26s
soaricarus_api CI / Check (push) Successful in 4m59s
soaricarus_api CI / Rustfmt (push) Successful in 2m26s
soaricarus_api CI / Clippy (push) Successful in 4m18s
soaricarus_api CI / build (push) Successful in 5m1s
soaricarus_api CI / Test Suite (push) Failing after 2m26s
Closes #268 Reviewed-on: http://git.kundeng.us/phoenix/soaricarus_api/pulls/269
This commit was merged in pull request #269.
This commit is contained in:
1 parent
728948ebe4
commit
23529e323a
5 files changed
+90
-9
No files matched your search
Generated
+1
-1
@@ -3190,7 +3190,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "soaricarus_api"
|
name = "soaricarus_api"
|
||||||
version = "0.5.11"
|
version = "0.5.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "soaricarus_api"
|
name = "soaricarus_api"
|
||||||
version = "0.5.11"
|
version = "0.5.12"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
rust-version = "1.95"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ Copy the `.env.docker.sample` file to `.env`. Ensure that the `ROOT_DIRECTORY` v
|
|||||||
and exists on the docker image's filesystem. The credentials for the database doesn't need to be
|
and exists on the docker image's filesystem. The credentials for the database doesn't need to be
|
||||||
changed for development, but if deploying it, it should be modified.
|
changed for development, but if deploying it, it should be modified.
|
||||||
|
|
||||||
|
### Authentication setup
|
||||||
|
Make sure the `SECRET_MAIN_KEY` variable in the `.env` file is at least **24** characters long
|
||||||
|
and it should match the same value as the `SECRET_KEY` variable from `soaricarus_auth`.
|
||||||
|
|
||||||
|
|
||||||
### S3 Setup
|
### S3 Setup
|
||||||
Using the copied `.env.docker.sample`, ensure that the following has been properly populated.
|
Using the copied `.env.docker.sample`, ensure that the following has been properly populated.
|
||||||
```
|
```
|
||||||
@@ -41,7 +46,7 @@ docker compose build --ssh default
|
|||||||
|
|
||||||
Bring it up
|
Bring it up
|
||||||
```
|
```
|
||||||
docker compose up -d --force-recreate
|
docker compose up
|
||||||
```
|
```
|
||||||
|
|
||||||
To view the OpenAPI spec, run the project and access `/swagger-ui`. If running through docker,
|
To view the OpenAPI spec, run the project and access `/swagger-ui`. If running through docker,
|
||||||
|
|||||||
+26
-6
@@ -11,6 +11,7 @@ pub mod request {
|
|||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||||
pub struct Params {
|
pub struct Params {
|
||||||
pub id: Option<uuid::Uuid>,
|
pub id: Option<uuid::Uuid>,
|
||||||
|
pub song_id: Option<uuid::Uuid>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,7 +182,8 @@ pub mod endpoint {
|
|||||||
get,
|
get,
|
||||||
path = super::super::endpoints::GETCOVERART,
|
path = super::super::endpoints::GETCOVERART,
|
||||||
params(
|
params(
|
||||||
("id" = uuid::Uuid, Path, description = "Cover art Id")
|
("id" = uuid::Uuid, Path, description = "Cover art Id"),
|
||||||
|
("song_id" = uuid::Uuid, Path, description = "Song Id")
|
||||||
),
|
),
|
||||||
responses(
|
responses(
|
||||||
(status = 200, description = "Cover art retrieved", body = super::response::get_coverart::Response),
|
(status = 200, description = "Cover art retrieved", body = super::response::get_coverart::Response),
|
||||||
@@ -201,7 +203,7 @@ pub mod endpoint {
|
|||||||
Some(id) => match repo::coverart::get_coverart(&pool, &id).await {
|
Some(id) => match repo::coverart::get_coverart(&pool, &id).await {
|
||||||
Ok(coverart) => {
|
Ok(coverart) => {
|
||||||
response.data.push(coverart);
|
response.data.push(coverart);
|
||||||
response.message = String::from(super::super::response::SUCCESSFUL);
|
response.message = super::super::response::SUCCESSFUL.to_string();
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -209,10 +211,28 @@ pub mod endpoint {
|
|||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
_ => match params.song_id {
|
||||||
response.message = String::from("Invalid parameters");
|
Some(song_id) => {
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
match repo::coverart::get_coverart_with_song_id(&pool, &song_id).await {
|
||||||
}
|
Ok(coverart) => {
|
||||||
|
response.data.push(coverart);
|
||||||
|
response.message = super::super::response::SUCCESSFUL.to_string();
|
||||||
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
response.message = "Invalid parameters".to_string();
|
||||||
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+56
@@ -2143,6 +2143,62 @@ mod tests {
|
|||||||
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
|
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_get_coverart_with_song_id() {
|
||||||
|
let tm_pool = super::db_mgr::get_pool().await.unwrap();
|
||||||
|
let db_name = super::db_mgr::generate_db_name().await;
|
||||||
|
|
||||||
|
match super::db_mgr::create_database(&tm_pool, &db_name).await {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Success");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {:?}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let pool = super::db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||||
|
super::db_mgr::migrations(&pool).await;
|
||||||
|
|
||||||
|
let app = super::init::app(pool).await;
|
||||||
|
|
||||||
|
let (song_id, _, _, _) = test_data::song_id().await.unwrap();
|
||||||
|
|
||||||
|
let uri = format!(
|
||||||
|
"{}?song_id={song_id}",
|
||||||
|
soaricarus_api::callers::endpoints::GETCOVERART
|
||||||
|
);
|
||||||
|
|
||||||
|
match app
|
||||||
|
.clone()
|
||||||
|
.oneshot(
|
||||||
|
super::request::run_post(None, &uri, axum::http::Method::GET, false)
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
let resp = super::util::get_resp_data::<
|
||||||
|
soaricarus_api::callers::coverart::response::get_coverart::Response,
|
||||||
|
>(response)
|
||||||
|
.await;
|
||||||
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
|
|
||||||
|
let coverart = resp.data[0].clone();
|
||||||
|
assert_eq!(
|
||||||
|
song_id, coverart.song_id,
|
||||||
|
"Song Id does not match {coverart:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||||
|
}
|
||||||
|
|
||||||
pub mod test_data {
|
pub mod test_data {
|
||||||
pub async fn song_id() -> Result<(uuid::Uuid, String, String, String), uuid::Error> {
|
pub async fn song_id() -> Result<(uuid::Uuid, String, String, String), uuid::Error> {
|
||||||
match uuid::Uuid::parse_str("44cf7940-34ff-489f-9124-d0ec90a55af9") {
|
match uuid::Uuid::parse_str("44cf7940-34ff-489f-9124-d0ec90a55af9") {
|
||||||
|
|||||||
Reference in new issue
Block a user