From 9f618d1db5640eb9dedfddac4c07ea35cf8ef470 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 20 May 2025 20:34:15 -0400 Subject: [PATCH] Code formatting --- src/callers/song.rs | 91 ++++++++++++++++++++++++++------------------- src/main.rs | 35 ++++++++++------- 2 files changed, 74 insertions(+), 52 deletions(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index c850211..902fae3 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -63,7 +63,6 @@ pub mod status { } } - mod song_queue { use sqlx::Row; @@ -153,50 +152,55 @@ mod song_queue { } } - pub async fn get_status_of_song_queue(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result { + pub async fn get_status_of_song_queue( + pool: &sqlx::PgPool, + id: &uuid::Uuid, + ) -> Result { let result = sqlx::query( r#" SELECT id, status FROM "songQueue" WHERE id = $1 "#, - ) - .bind(id) - .fetch_one(pool) - .await - .map_err(|e| { - eprintln!("Error selecting: {:?}", e); - }); + ) + .bind(id) + .fetch_one(pool) + .await + .map_err(|e| { + eprintln!("Error selecting: {:?}", e); + }); match result { - Ok(row) => { - Ok(row.try_get("status").map_err(|_e| sqlx::Error::RowNotFound).unwrap()) - } - Err(_err) => { - Err(sqlx::Error::RowNotFound) - } + Ok(row) => Ok(row + .try_get("status") + .map_err(|_e| sqlx::Error::RowNotFound) + .unwrap()), + Err(_err) => Err(sqlx::Error::RowNotFound), } } - pub async fn update_song_queue_status(pool: &sqlx::PgPool, status: &String, id: &uuid::Uuid) -> Result { + pub async fn update_song_queue_status( + pool: &sqlx::PgPool, + status: &String, + id: &uuid::Uuid, + ) -> Result { let result = sqlx::query( r#" UPDATE "songQueue" SET status = $1 WHERE id = $2 RETURNING status; "#, - ) - .bind(status) - .bind(id) - .fetch_one(pool) - .await - .map_err(|e| { - eprintln!("Error updating record {:?}", e); - }); + ) + .bind(status) + .bind(id) + .fetch_one(pool) + .await + .map_err(|e| { + eprintln!("Error updating record {:?}", e); + }); match result { - Ok(row) => { - Ok(row.try_get("status").map_err(|_e| sqlx::Error::RowNotFound).unwrap()) - } - Err(_) => { - Err(sqlx::Error::RowNotFound) - } + Ok(row) => Ok(row + .try_get("status") + .map_err(|_e| sqlx::Error::RowNotFound) + .unwrap()), + Err(_) => Err(sqlx::Error::RowNotFound), } } @@ -330,9 +334,12 @@ pub mod endpoint { } pub async fn update_song_queue_status( - axum::Extension(pool): axum::Extension, - axum::Json(payload): axum::Json, - ) -> (axum::http::StatusCode, axum::Json) { + axum::Extension(pool): axum::Extension, + axum::Json(payload): axum::Json, + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { let mut response = super::response::update_status::Response::default(); if super::status::is_valid(&payload.status).await { @@ -340,13 +347,21 @@ pub mod endpoint { if !id.is_nil() { match super::song_queue::get_status_of_song_queue(&pool, &id).await { Ok(old) => { - match super::song_queue::update_song_queue_status(&pool, &payload.status, &id).await { + match super::song_queue::update_song_queue_status( + &pool, + &payload.status, + &id, + ) + .await + { Ok(new) => { response.message = String::from("Successful"); - response.data.push(super::response::update_status::ChangedStatus{ - old_status: old, - new_status: new - }); + response + .data + .push(super::response::update_status::ChangedStatus { + old_status: old, + new_status: new, + }); (axum::http::StatusCode::OK, axum::Json(response)) } Err(err) => { diff --git a/src/main.rs b/src/main.rs index fc4e37a..c68d9f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -802,22 +802,29 @@ mod tests { .body(axum::body::Body::from(payload.to_string())) .unwrap(), ) - .await { - Ok(response) => { - let resp = get_resp_data::< - crate::callers::song::response::update_status::Response, - >(response) - .await; - assert_eq!(false, resp.data.is_empty(), "Should not be empty"); - let changed_status = &resp.data[0]; + .await + { + Ok(response) => { + let resp = get_resp_data::< + crate::callers::song::response::update_status::Response, + >(response) + .await; + assert_eq!(false, resp.data.is_empty(), "Should not be empty"); + let changed_status = &resp.data[0]; - assert_eq!(*old, changed_status.old_status, "Old status does not match"); - assert_eq!(done, changed_status.new_status, "New status does not match"); - } - Err(err) => { - assert!(false, "Error: {:?}", err); - } + assert_eq!( + *old, changed_status.old_status, + "Old status does not match" + ); + assert_eq!( + done, changed_status.new_status, + "New status does not match" + ); } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } } Err(err) => { assert!(false, "Error: {:?}", err);