From c7809a44cf1830ba06fb793ab6130cf078131b39 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 26 May 2025 16:50:42 -0400 Subject: [PATCH] Code formatting --- src/callers/coverart.rs | 72 +++++++++++++++++++++-------------------- src/main.rs | 42 ++++++++++++++++++------ 2 files changed, 70 insertions(+), 44 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index c0e73e2..6336d4d 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -42,7 +42,7 @@ pub mod request { pub mod wipe_data_from_coverart_queue { #[derive(Debug, serde::Deserialize, serde::Serialize)] pub struct Request { - pub coverart_queue_id: uuid::Uuid + pub coverart_queue_id: uuid::Uuid, } } } @@ -262,26 +262,28 @@ pub mod db { } } - pub async fn wipe_data(pool: &sqlx::PgPool, coverart_queue_id: &uuid::Uuid) -> Result { + pub async fn wipe_data( + pool: &sqlx::PgPool, + coverart_queue_id: &uuid::Uuid, + ) -> Result { let result = sqlx::query( r#" UPDATE "coverartQueue" SET data = NULL WHERE id = $1 RETURNING id; - "# - ) - .bind(coverart_queue_id) - .fetch_one(pool) - .await - .map_err(|e| { - eprintln!("Error updating query: {:?}", e); - }); + "#, + ) + .bind(coverart_queue_id) + .fetch_one(pool) + .await + .map_err(|e| { + eprintln!("Error updating query: {:?}", e); + }); match result { - Ok(row) => { - Ok(row.try_get("id").map_err(|_e| sqlx::Error::RowNotFound).unwrap()) - } - Err(_) => { - Err(sqlx::Error::RowNotFound) - } + Ok(row) => Ok(row + .try_get("id") + .map_err(|_e| sqlx::Error::RowNotFound) + .unwrap()), + Err(_) => Err(sqlx::Error::RowNotFound), } } } @@ -547,32 +549,32 @@ pub mod endpoint { } } - pub async fn wipe_data_from_coverart_queue(axum::Extension(pool): axum::Extension, - axum::Json(payload): axum::Json,) -> ( + pub async fn wipe_data_from_coverart_queue( + axum::Extension(pool): axum::Extension, + axum::Json(payload): axum::Json, + ) -> ( axum::http::StatusCode, axum::Json, - ) { - let mut response = super::response::wipe_data_from_coverart_queue::Response::default(); - let coverart_queue_id = payload.coverart_queue_id; + ) { + let mut response = super::response::wipe_data_from_coverart_queue::Response::default(); + let coverart_queue_id = payload.coverart_queue_id; - match super::db::get_coverart_queue_with_id(&pool, &coverart_queue_id).await { - Ok(coverart_queue) => { - match super::db::wipe_data(&pool, &coverart_queue.id).await { - Ok(id) => { - response.message = String::from("Success"); - response.data.push(id); - (axum::http::StatusCode::OK, axum::Json(response)) - } - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } + match super::db::get_coverart_queue_with_id(&pool, &coverart_queue_id).await { + Ok(coverart_queue) => match super::db::wipe_data(&pool, &coverart_queue.id).await { + Ok(id) => { + response.message = String::from("Success"); + response.data.push(id); + (axum::http::StatusCode::OK, axum::Json(response)) } Err(err) => { response.message = err.to_string(); - (axum::http::StatusCode::NOT_FOUND, axum::Json(response)) + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } + }, + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::NOT_FOUND, axum::Json(response)) } + } } } diff --git a/src/main.rs b/src/main.rs index 38fa2e4..869096b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,9 +101,10 @@ pub mod init { crate::callers::endpoints::QUEUECOVERARTLINK, patch(crate::callers::coverart::endpoint::link), ) - .route(crate::callers::endpoints::QUEUECOVERARTDATAWIPE, - patch(crate::callers::coverart::endpoint::wipe_data_from_coverart_queue) - ) + .route( + crate::callers::endpoints::QUEUECOVERARTDATAWIPE, + patch(crate::callers::coverart::endpoint::wipe_data_from_coverart_queue), + ) .route( crate::callers::endpoints::CREATESONG, post(crate::callers::song::endpoint::create_metadata), @@ -371,8 +372,11 @@ mod tests { app.clone().oneshot(req).await } - - async fn create_coverart_req(app: &axum::Router, song_id: &uuid::Uuid, coverart_id: &uuid::Uuid) -> Result { + async fn create_coverart_req( + app: &axum::Router, + song_id: &uuid::Uuid, + coverart_id: &uuid::Uuid, + ) -> Result { let payload = serde_json::json!({ "song_id": song_id, "coverart_queue_id": coverart_id @@ -1472,7 +1476,13 @@ mod tests { "Should not be empty" ); - match create_coverart_req(&app, &song_id, &resp_coverart_id).await { + match create_coverart_req( + &app, + &song_id, + &resp_coverart_id, + ) + .await + { Ok(response) => { let resp = get_resp_data::< crate::callers::coverart::response::create_coverart::Response, @@ -1485,7 +1495,11 @@ mod tests { ); } Err(err) => { - assert!(false, "Error: {:?}", err); + assert!( + false, + "Error: {:?}", + err + ); } } } @@ -1781,7 +1795,13 @@ mod tests { "Should not be empty" ); - match create_coverart_req(&app, &song_id, &resp_coverart_id).await { + match create_coverart_req( + &app, + &song_id, + &resp_coverart_id, + ) + .await + { Ok(response) => { let resp = get_resp_data::< crate::callers::coverart::response::create_coverart::Response, @@ -1822,7 +1842,11 @@ mod tests { } } Err(err) => { - assert!(false, "Error: {:?}", err); + assert!( + false, + "Error: {:?}", + err + ); } } }