tsk-268: Extend get cover art #269
+23
-3
@@ -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))
|
||||||
}
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user