From 09d7fa32c89ddf5ab3b9207c8198836fad79c451 Mon Sep 17 00:00:00 2001 From: KD Date: Wed, 29 Oct 2025 15:20:04 -0400 Subject: [PATCH] tsk-179: Modify status code of song queue endpoint (#226) * tsk-179: Updating docs for endpoint status codes * tsk-179: Updated status code * tsk-179: Improved error handling * tsk-179: Code formatting * tsk-179: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/callers/queue/song.rs | 25 +++++++++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee7173a..426ba54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -834,7 +834,7 @@ dependencies = [ [[package]] name = "icarus" -version = "0.3.10" +version = "0.3.11" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index 55321cd..d81ea78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus" -version = "0.3.10" +version = "0.3.11" edition = "2024" rust-version = "1.90" diff --git a/src/callers/queue/song.rs b/src/callers/queue/song.rs index 1dcf38d..bb280f9 100644 --- a/src/callers/queue/song.rs +++ b/src/callers/queue/song.rs @@ -124,7 +124,9 @@ pub mod endpoint { content_type = "multipart/form-data" ), responses( - (status = 200, description = "Song queued", body = super::response::song_queue::Response) + (status = 201, description = "Song queued", body = super::response::song_queue::Response), + (status = 400, description = "Invalid request passed", body = super::response::song_queue::Response), + (status = 500, description = "Error queueing song", body = super::response::song_queue::Response) ) )] pub async fn queue_song( @@ -155,15 +157,25 @@ pub mod endpoint { match super::is_song_valid(&raw_data).await { Ok(valid) => { if valid { - let queue_repo = repo::song::insert( + match repo::song::insert( &pool, &raw_data, &file_name, &crate::repo::queue::song::status::PENDING.to_string(), ) .await - .unwrap(); - results.push(queue_repo); + { + Ok(queued_song) => { + results.push(queued_song); + } + Err(err) => { + response.message = err.to_string(); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ); + } + } } else { response.message = String::from("Invalid song type"); return (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)); @@ -186,7 +198,7 @@ pub mod endpoint { String::from(super::super::super::response::SUCCESSFUL) }; - (axum::http::StatusCode::OK, axum::Json(response)) + (axum::http::StatusCode::CREATED, axum::Json(response)) } /// Endpoint to link a user id to a queued song @@ -379,7 +391,8 @@ pub mod endpoint { responses( (status = 200, description = "Queued song updated", body = super::response::update_song_queue::Response), (status = 400, description = "Error updating queued song", body = super::response::update_song_queue::Response), - (status = 404, description = "Queued song not found", body = super::response::update_song_queue::Response) + (status = 404, description = "Queued song not found", body = super::response::update_song_queue::Response), + (status = 500, description = "Error updating queued song", body = super::response::update_song_queue::Response) ) )] pub async fn update_song_queue(