From b93db64c208d12d350d66999106575a2c51a5eba Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Thu, 22 May 2025 16:13:06 -0400 Subject: [PATCH] Code formatting --- src/callers/song.rs | 41 ++++++++++++++++++++--------------------- src/main.rs | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index d29cf3f..a638274 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -118,25 +118,26 @@ mod song_queue { pool: &sqlx::PgPool, data: &Vec, id: &uuid::Uuid, - ) -> Result, sqlx::Error> { + ) -> Result, sqlx::Error> { let result = sqlx::query( r#" UPDATE "songQueue" SET data = $1 WHERE id = $2 RETURNING data; - "# - ) - .bind(data) - .bind(id) - .fetch_one(pool) - .await - .map_err(|e| { - eprintln!("Error inserting: {:?}", e); - }); + "#, + ) + .bind(data) + .bind(id) + .fetch_one(pool) + .await + .map_err(|e| { + eprintln!("Error inserting: {:?}", e); + }); match result { - Ok(row) => { - Ok(row.try_get("data").map_err(|_e| sqlx::Error::RowNotFound).unwrap()) - } - Err(_) => Err(sqlx::Error::RowNotFound) + Ok(row) => Ok(row + .try_get("data") + .map_err(|_e| sqlx::Error::RowNotFound) + .unwrap()), + Err(_) => Err(sqlx::Error::RowNotFound), } } @@ -419,8 +420,10 @@ pub mod endpoint { axum::extract::Path(id): axum::extract::Path, axum::Extension(pool): axum::Extension, mut multipart: axum::extract::Multipart, - ) -> (axum::http::StatusCode, axum::Json) { - + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { let mut response = super::response::update_song_queue::Response::default(); if let Some(field) = multipart.next_field().await.unwrap() { @@ -442,11 +445,7 @@ pub mod endpoint { // file.write_all(&data).unwrap(); let raw_data: Vec = data.to_vec(); - match song_queue::update( - &pool, - &raw_data, - &id, - ).await { + match song_queue::update(&pool, &raw_data, &id).await { Ok(queued_data) => { response.data.push(queued_data); (axum::http::StatusCode::OK, axum::Json(response)) diff --git a/src/main.rs b/src/main.rs index 8d01730..c2994cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,7 +83,7 @@ pub mod init { ) .route( crate::callers::endpoints::QUEUESONGUPDATE, - patch(crate::callers::song::endpoint::update_song_queue) + patch(crate::callers::song::endpoint::update_song_queue), ) .route( crate::callers::endpoints::QUEUEMETADATA, @@ -1124,7 +1124,8 @@ mod tests { // let new_file = String::from("tests/Machine_gun/new_file.flac"); - let temp_file = tempfile::tempdir().expect("Could not create test directory"); + let temp_file = tempfile::tempdir() + .expect("Could not create test directory"); let test_dir = String::from(temp_file.path().to_str().unwrap()); let new_file = format!("{}/new_file.flac", test_dir); @@ -1138,28 +1139,44 @@ mod tests { let content_type = form.content_type(); let body = MultipartBody::from(form); - let raw_uri = String::from(crate::callers::endpoints::QUEUESONGUPDATE); + let raw_uri = + String::from(crate::callers::endpoints::QUEUESONGUPDATE); let end_index = raw_uri.len() - 5; // let mut uri: String = (&raw_uri[..end_index]).to_string(); // uri += &id.to_string(); - let uri = format!("{}/{}", (&raw_uri[..end_index]).to_string(), id.to_string()); + let uri = format!( + "{}/{}", + (&raw_uri[..end_index]).to_string(), + id.to_string() + ); // app.clone().oneshot(req).await - match app.clone().oneshot( - axum::http::Request::builder() - .method(axum::http::Method::PATCH) - .uri(uri) - .header(axum::http::header::CONTENT_TYPE, content_type) - .body(axum::body::Body::from_stream(body)) - .unwrap() - ).await { + match app + .clone() + .oneshot( + axum::http::Request::builder() + .method(axum::http::Method::PATCH) + .uri(uri) + .header( + axum::http::header::CONTENT_TYPE, + content_type, + ) + .body(axum::body::Body::from_stream(body)) + .unwrap(), + ) + .await + { Ok(response) => { let resp = get_resp_data::< crate::callers::song::response::update_song_queue::Response, >(response) .await; - assert_eq!(false, resp.data.is_empty(), "Should not be empty"); + assert_eq!( + false, + resp.data.is_empty(), + "Should not be empty" + ); } Err(err) => { assert!(false, "Error: {:?}", err);