From aa4b7d34db256d7d4857539f9380ff3b07b77682 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 10 Nov 2026 21:44:40 -0500 Subject: [PATCH] tsk-14: cargo fmt --- src/callers/login.rs | 36 +++++++++++++++++++++++++----------- src/main.rs | 30 +++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/callers/login.rs b/src/callers/login.rs index 8a9f8f5..5f89f72 100644 --- a/src/callers/login.rs +++ b/src/callers/login.rs @@ -51,7 +51,7 @@ pub mod request { pub struct UpdateUserProfileRequest { pub user_id: uuid::Uuid, pub firstname: String, - pub lastname: String + pub lastname: String, } impl UpdateUserProfileRequest { @@ -115,7 +115,6 @@ pub mod response { pub message: String, pub data: Vec, } - } } @@ -489,10 +488,17 @@ pub mod endpoint { (status = 500, description = "Failure", body = super::response::update_user_profile::UpdateUserProfileResponse) ) )] - pub async fn update_user_profile(axum::Extension(pool): axum::Extension, - axum::Json(payload): axum::Json, - ) -> (axum::http::StatusCode, axum::Json,) { - let mut response = super::response::update_user_profile::UpdateUserProfileResponse::default(); + pub async fn update_user_profile( + axum::Extension(pool): axum::Extension, + axum::Json(payload): axum::Json< + super::request::update_user_profile::UpdateUserProfileRequest, + >, + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { + let mut response = + super::response::update_user_profile::UpdateUserProfileResponse::default(); if !payload.is_valid() { response.message = "Invalid".to_string(); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) @@ -502,7 +508,9 @@ pub mod endpoint { Ok(user) => { let firstname = payload.firstname; let lastname = payload.lastname; - match repo::user::update_user_profile(&pool, &user_id, &firstname, &lastname).await { + match repo::user::update_user_profile(&pool, &user_id, &firstname, &lastname) + .await + { Ok(_) => { let user_profile = simodels::user::UserProfile { firstname, @@ -513,18 +521,24 @@ pub mod endpoint { response.message = "SUCCESSFUL".to_string(); response.data.push(user_profile); (axum::http::StatusCode::OK, axum::Json(response)) - }, + } Err(err) => { eprintln!("Error: {err:?}"); response.message = "ERROR - Updating user profile".to_string(); - (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) + ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ) } } - }, + } Err(err) => { eprintln!("Error: {err:?}"); response.message = "ERROR".to_string(); - (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response)) + ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ) } } } diff --git a/src/main.rs b/src/main.rs index 3ef50e3..f9e053a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,6 @@ async fn main() { axum::serve(listener, app).await.unwrap(); } - #[cfg(test)] mod tests { use super::*; @@ -144,7 +143,11 @@ mod tests { }) } - pub fn update_user_profile(user_id: &uuid::Uuid, firstname: &str, lastname: &str) -> serde_json::Value { + pub fn update_user_profile( + user_id: &uuid::Uuid, + firstname: &str, + lastname: &str, + ) -> serde_json::Value { json!({ "firstname": firstname, "lastname": lastname, @@ -154,8 +157,8 @@ mod tests { } pub mod requests { - use tower::ServiceExt; // for `call`, `oneshot`, and `ready` use soaricarus_auth::callers; + use tower::ServiceExt; // for `call`, `oneshot`, and `ready` pub async fn register( app: &axum::Router, @@ -671,7 +674,7 @@ mod tests { let body = axum::body::to_bytes(resp.into_body(), usize::MAX) .await .unwrap(); - + let parsed_body: responses::login_responses::get_user_profile::GetUserProfileResponse = serde_json::from_slice(&body).unwrap(); let user_profile = &parsed_body.data[0]; @@ -746,7 +749,14 @@ mod tests { let updated_firstname = test_data::UPDATED_FIRSTNAME; let updated_lastname = test_data::UPDATED_LASTNAME; - match requests::update_user_profile(&app, &user_id, &updated_firstname, &updated_lastname).await { + match requests::update_user_profile( + &app, + &user_id, + &updated_firstname, + &updated_lastname, + ) + .await + { Ok(resp) => { assert_eq!(StatusCode::OK, resp.status(), "Status is not right"); let body = axum::body::to_bytes(resp.into_body(), usize::MAX) @@ -757,8 +767,14 @@ mod tests { serde_json::from_slice(&body).unwrap(); let user_profile = &parsed_body.data[0]; - assert_eq!(updated_firstname, user_profile.firstname, "Firstname has not been updated"); - assert_eq!(updated_lastname, user_profile.lastname, "Lastname has not been updated"); + assert_eq!( + updated_firstname, user_profile.firstname, + "Firstname has not been updated" + ); + assert_eq!( + updated_lastname, user_profile.lastname, + "Lastname has not been updated" + ); } Err(err) => { assert!(false, "Error: {:?}", err.to_string());