Code formatting

This commit is contained in:
kdeng00
2025-07-26 14:08:06 -04:00
parent 4dd9a3ba16
commit 84c0bc2d08
2 changed files with 31 additions and 21 deletions
+20 -10
View File
@@ -111,7 +111,7 @@ pub mod response {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)] #[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct Response { pub struct Response {
pub message: String, pub message: String,
pub data: Vec<icarus_models::coverart::CoverArt> pub data: Vec<icarus_models::coverart::CoverArt>,
} }
} }
} }
@@ -337,7 +337,10 @@ pub mod cov_db {
} }
} }
pub async fn get_coverart(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> { pub async fn get_coverart(
pool: &sqlx::PgPool,
id: &uuid::Uuid,
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
let result = sqlx::query( let result = sqlx::query(
r#" r#"
SELECT id, title, path, song_id FROM "coverart" WHERE id = $1; SELECT id, title, path, song_id FROM "coverart" WHERE id = $1;
@@ -360,9 +363,15 @@ pub mod cov_db {
.try_get("title") .try_get("title")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
.unwrap(), .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(), 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), Err(_) => Err(sqlx::Error::RowNotFound),
} }
@@ -609,13 +618,15 @@ pub mod endpoint {
pub async fn get_coverart( pub async fn get_coverart(
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::extract::Query(params): axum::extract::Query<super::request::get_coverart::Params> axum::extract::Query(params): axum::extract::Query<super::request::get_coverart::Params>,
) -> (axum::http::StatusCode, axum::Json<super::response::get_coverart::Response>) { ) -> (
axum::http::StatusCode,
axum::Json<super::response::get_coverart::Response>,
) {
let mut response = super::response::get_coverart::Response::default(); let mut response = super::response::get_coverart::Response::default();
match params.id { match params.id {
Some(id) => { Some(id) => match super::cov_db::get_coverart(&pool, &id).await {
match super::cov_db::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 = String::from(super::super::response::SUCCESSFUL);
@@ -625,8 +636,7 @@ pub mod endpoint {
response.message = err.to_string(); response.message = err.to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) (axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
} }
} },
}
None => { None => {
response.message = String::from("Invalid parameters"); response.message = String::from("Invalid parameters");
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) (axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
+1 -1
View File
@@ -121,7 +121,7 @@ pub mod init {
) )
.route( .route(
crate::callers::endpoints::GETCOVERART, crate::callers::endpoints::GETCOVERART,
get(crate::callers::coverart::endpoint::get_coverart) get(crate::callers::coverart::endpoint::get_coverart),
) )
} }