diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 08b9f43..31f8045 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -111,7 +111,7 @@ pub mod response { #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] pub struct Response { pub message: String, - pub data: Vec + pub data: Vec, } } } @@ -337,7 +337,10 @@ pub mod cov_db { } } - pub async fn get_coverart(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result { + pub async fn get_coverart( + pool: &sqlx::PgPool, + id: &uuid::Uuid, + ) -> Result { let result = sqlx::query( r#" SELECT id, title, path, song_id FROM "coverart" WHERE id = $1; @@ -360,9 +363,15 @@ pub mod cov_db { .try_get("title") .map_err(|_e| sqlx::Error::RowNotFound) .unwrap(), - path: row.try_get("path").map_err(|_e| sqlx::Error::RowNotFound).unwrap(), + path: row + .try_get("path") + .map_err(|_e| sqlx::Error::RowNotFound) + .unwrap(), data: Vec::new(), - song_id: row.try_get("song_id").map_err(|_e| sqlx::Error::RowNotFound).unwrap() + song_id: row + .try_get("song_id") + .map_err(|_e| sqlx::Error::RowNotFound) + .unwrap(), }), Err(_) => Err(sqlx::Error::RowNotFound), } @@ -609,24 +618,25 @@ pub mod endpoint { pub async fn get_coverart( axum::Extension(pool): axum::Extension, - axum::extract::Query(params): axum::extract::Query - ) -> (axum::http::StatusCode, axum::Json) { + axum::extract::Query(params): axum::extract::Query, + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { let mut response = super::response::get_coverart::Response::default(); match params.id { - Some(id) => { - match super::cov_db::get_coverart(&pool, &id).await { - Ok(coverart) => { - response.data.push(coverart); - response.message = String::from(super::super::response::SUCCESSFUL); - (axum::http::StatusCode::OK, axum::Json(response)) - } - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } + Some(id) => match super::cov_db::get_coverart(&pool, &id).await { + Ok(coverart) => { + response.data.push(coverart); + response.message = String::from(super::super::response::SUCCESSFUL); + (axum::http::StatusCode::OK, axum::Json(response)) } - } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + }, None => { response.message = String::from("Invalid parameters"); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) diff --git a/src/main.rs b/src/main.rs index 3320c30..4e8798e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -121,8 +121,8 @@ pub mod init { ) .route( crate::callers::endpoints::GETCOVERART, - get(crate::callers::coverart::endpoint::get_coverart) - ) + get(crate::callers::coverart::endpoint::get_coverart), + ) } pub async fn app() -> axum::Router { @@ -1902,7 +1902,7 @@ mod tests { let app = super::init::app(pool).await; let mut id = uuid::Uuid::nil(); - + match uuid::Uuid::parse_str("996122cd-5ae9-4013-9934-60768d3006ed") { Ok(val) => { id = val;