tsk-179: Modify status code of song queue endpoint #226

Merged
kdeng00 merged 5 commits from tsk-179 into main 2025-10-29 15:20:04 -04:00
3 changed files with 21 additions and 8 deletions
Generated
+1 -1
View File
@@ -834,7 +834,7 @@ dependencies = [
[[package]] [[package]]
name = "icarus" name = "icarus"
version = "0.3.10" version = "0.3.11"
dependencies = [ dependencies = [
"axum", "axum",
"axum-extra", "axum-extra",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "icarus" name = "icarus"
version = "0.3.10" version = "0.3.11"
edition = "2024" edition = "2024"
rust-version = "1.90" rust-version = "1.90"
+19 -6
View File
@@ -124,7 +124,9 @@ pub mod endpoint {
content_type = "multipart/form-data" content_type = "multipart/form-data"
), ),
responses( 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( pub async fn queue_song(
@@ -155,15 +157,25 @@ pub mod endpoint {
match super::is_song_valid(&raw_data).await { match super::is_song_valid(&raw_data).await {
Ok(valid) => { Ok(valid) => {
if valid { if valid {
let queue_repo = repo::song::insert( match repo::song::insert(
&pool, &pool,
&raw_data, &raw_data,
&file_name, &file_name,
&crate::repo::queue::song::status::PENDING.to_string(), &crate::repo::queue::song::status::PENDING.to_string(),
) )
.await .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 { } else {
response.message = String::from("Invalid song type"); response.message = String::from("Invalid song type");
return (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)); return (axum::http::StatusCode::BAD_REQUEST, axum::Json(response));
@@ -186,7 +198,7 @@ pub mod endpoint {
String::from(super::super::super::response::SUCCESSFUL) 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 /// Endpoint to link a user id to a queued song
@@ -379,7 +391,8 @@ pub mod endpoint {
responses( responses(
(status = 200, description = "Queued song updated", body = super::response::update_song_queue::Response), (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 = 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( pub async fn update_song_queue(