From 1281913c36e63a7bd939b5f922242cfdcd9abfa4 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 25 Jul 2025 16:35:29 -0400 Subject: [PATCH] Added more code --- src/callers/song.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index 823cd88..1656668 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -170,7 +170,7 @@ pub mod response { #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] pub struct Response { pub message: String, - pub data: Vec, + pub data: Vec, } } } @@ -993,6 +993,23 @@ pub mod endpoint { ) { let mut response = super::response::get_songs::Response::default(); - (axum::http::StatusCode::OK, axum::Json(response)) + match params.id { + Some(id) => { + match super::song_db::get_song(&pool, &id).await { + Ok(song) => { + response.data.push(song); + (axum::http::StatusCode::OK, axum::Json(response)) + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + } + None => { + response.message = String::from("Invalid parameters"); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } } }