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

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:
phoenix committed 2026-11-07 13:35:52 -05:00
1 parent 728948ebe4
commit 23529e323a
5 files changed
+87 -6

No files matched your search

Generated
+1 -1
View File
@@ -3190,7 +3190,7 @@ dependencies = [
[[package]]
name = "soaricarus_api"
version = "0.5.11"
version = "0.5.12"
dependencies = [
"axum",
"axum-extra",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "soaricarus_api"
version = "0.5.11"
version = "0.5.12"
edition = "2024"
rust-version = "1.95"
license = "MIT"
+6 -1
View File
@@ -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
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
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
```
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,
+23 -3
View File
@@ -11,6 +11,7 @@ pub mod request {
#[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct Params {
pub id: Option<uuid::Uuid>,
pub song_id: Option<uuid::Uuid>,
}
}
}
@@ -181,7 +182,8 @@ pub mod endpoint {
get,
path = super::super::endpoints::GETCOVERART,
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(
(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 {
Ok(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))
}
Err(err) => {
@@ -209,10 +211,28 @@ pub mod endpoint {
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
},
_ => match params.song_id {
Some(song_id) => {
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 = String::from("Invalid parameters");
response.message = "Invalid parameters".to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
},
}
}
+56
View File
@@ -2143,6 +2143,62 @@ mod tests {
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 async fn song_id() -> Result<(uuid::Uuid, String, String, String), uuid::Error> {
match uuid::Uuid::parse_str("44cf7940-34ff-489f-9124-d0ec90a55af9") {