tsk-268: Extend get cover art #269

Merged
phoenix merged 5 commits from tsk-268 into main 2026-11-07 13:35:52 -05:00
5 changed files with 87 additions and 6 deletions

No files matched your search

Generated
+1 -1
View File
@@ -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
View File
@@ -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"
+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 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,
+23 -3
View File
@@ -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))
} }
}, },
_ => 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 => { None => {
response.message = String::from("Invalid parameters"); response.message = "Invalid parameters".to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) (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; 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") {