From 1a5a9fcaafffb7f5ae4ceb127de12cbdd8eb2cdb Mon Sep 17 00:00:00 2001 From: KD Date: Mon, 27 Oct 2025 13:25:30 -0400 Subject: [PATCH] tsk-194: Make distinction in MetadataQueue endpoints (#222) * tsk-194: Moving metadata module * tsk-194: Build fix * tsk-194: Name changes * tsk-194: Code formatting * tsk-194: Version bump * tsk-194: Test fixes --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/callers/mod.rs | 3 -- src/callers/{ => queue}/metadata.rs | 45 ++++++++++++++--------------- src/callers/queue/mod.rs | 2 ++ src/callers/song.rs | 3 +- src/main.rs | 38 +++++++++++++----------- 7 files changed, 49 insertions(+), 46 deletions(-) rename src/callers/{ => queue}/metadata.rs (82%) diff --git a/Cargo.lock b/Cargo.lock index b6f7f1a..a7fc01e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -834,7 +834,7 @@ dependencies = [ [[package]] name = "icarus" -version = "0.3.7" +version = "0.3.8" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index 55e5d40..b70249a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus" -version = "0.3.7" +version = "0.3.8" edition = "2024" rust-version = "1.90" diff --git a/src/callers/mod.rs b/src/callers/mod.rs index 217840b..542c384 100644 --- a/src/callers/mod.rs +++ b/src/callers/mod.rs @@ -1,11 +1,8 @@ pub mod coverart; -pub mod metadata; pub mod queue; pub mod song; pub mod endpoints { - pub const QUEUEMETADATA: &str = "/api/v2/song/metadata/queue"; - pub const CREATESONG: &str = "/api/v2/song"; pub const GETSONGS: &str = "/api/v2/song"; pub const GETALLSONGS: &str = "/api/v2/song/all"; diff --git a/src/callers/metadata.rs b/src/callers/queue/metadata.rs similarity index 82% rename from src/callers/metadata.rs rename to src/callers/queue/metadata.rs index 6dd627f..aedd4c1 100644 --- a/src/callers/metadata.rs +++ b/src/callers/queue/metadata.rs @@ -1,9 +1,8 @@ -// TODO: Explicitly make this module target queueing a song's metadata pub mod request { pub mod queue_metadata { - use serde::{Deserialize, Serialize}; - - #[derive(Debug, Default, Deserialize, Serialize, sqlx::FromRow, utoipa::ToSchema)] + #[derive( + Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema, + )] pub struct Request { pub song_queue_id: uuid::Uuid, pub album: String, @@ -59,9 +58,7 @@ pub mod request { pub mod response { pub mod queue_metadata { - use serde::{Deserialize, Serialize}; - - #[derive(Default, Deserialize, Serialize, utoipa::ToSchema)] + #[derive(Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, pub data: Vec, @@ -69,9 +66,7 @@ pub mod response { } pub mod fetch_metadata { - use serde::{Deserialize, Serialize}; - - #[derive(Default, Deserialize, Serialize, utoipa::ToSchema)] + #[derive(Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, pub data: Vec, @@ -81,8 +76,6 @@ pub mod response { /// Module for metadata related endpoints pub mod endpoint { - use axum::{Json, http::StatusCode}; - use crate::repo::queue as repo_queue; /// Endpoint to create queued metadata @@ -101,8 +94,11 @@ pub mod endpoint { )] pub async fn queue_metadata( axum::Extension(pool): axum::Extension, - Json(payload): Json, - ) -> (StatusCode, Json) { + axum::Json(payload): axum::Json, + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { let mut results: Vec = Vec::new(); let mut response = super::response::queue_metadata::Response::default(); let meta = payload.to_json_value().await; @@ -113,14 +109,14 @@ pub mod endpoint { response.message = if response.data.is_empty() { String::from("Error") } else { - String::from(super::super::response::SUCCESSFUL) + String::from(super::super::super::response::SUCCESSFUL) }; - (StatusCode::OK, Json(response)) + (axum::http::StatusCode::OK, axum::Json(response)) } Err(err) => { response.message = err.to_string(); - (StatusCode::BAD_REQUEST, Json(response)) + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } } } @@ -141,7 +137,10 @@ pub mod endpoint { pub async fn fetch_metadata( axum::Extension(pool): axum::Extension, axum::extract::Query(params): axum::extract::Query, - ) -> (StatusCode, Json) { + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { let mut response = super::response::fetch_metadata::Response::default(); match params.id { @@ -152,11 +151,11 @@ pub mod endpoint { Ok(item) => { response.message = String::from("Successful"); response.data.push(item); - (StatusCode::OK, Json(response)) + (axum::http::StatusCode::OK, axum::Json(response)) } Err(err) => { response.message = err.to_string(); - (StatusCode::BAD_REQUEST, Json(response)) + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } } } @@ -168,17 +167,17 @@ pub mod endpoint { Ok(item) => { response.message = String::from("Successful"); response.data.push(item); - (StatusCode::OK, Json(response)) + (axum::http::StatusCode::OK, axum::Json(response)) } Err(err) => { response.message = err.to_string(); - (StatusCode::BAD_REQUEST, Json(response)) + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } } } None => { println!("What is going on?"); - (StatusCode::BAD_REQUEST, Json(response)) + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) } }, } diff --git a/src/callers/queue/mod.rs b/src/callers/queue/mod.rs index b47a5ca..12e2982 100644 --- a/src/callers/queue/mod.rs +++ b/src/callers/queue/mod.rs @@ -1,4 +1,5 @@ pub mod coverart; +pub mod metadata; pub mod song; pub mod endpoints { @@ -7,6 +8,7 @@ pub mod endpoints { pub const QUEUESONGDATA: &str = "/api/v2/song/queue/{id}"; pub const QUEUESONGUPDATE: &str = "/api/v2/song/queue/{id}"; pub const NEXTQUEUESONG: &str = "/api/v2/song/queue/next"; + pub const QUEUEMETADATA: &str = "/api/v2/song/metadata/queue"; pub const QUEUECOVERART: &str = "/api/v2/coverart/queue"; pub const QUEUECOVERARTDATA: &str = "/api/v2/coverart/queue/data/{id}"; pub const QUEUECOVERARTLINK: &str = "/api/v2/coverart/queue/link"; diff --git a/src/callers/song.rs b/src/callers/song.rs index 0d8c605..db97d00 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -107,10 +107,11 @@ pub mod endpoint { use crate::repo; use crate::repo::queue as repo_queue; + // TODO: Change the name of this endpoint. Including the function name and path /// Endpoint to create song #[utoipa::path( post, - path = super::super::endpoints::QUEUEMETADATA, + path = super::super::queue::endpoints::QUEUEMETADATA, request_body( content = super::request::create_metadata::Request, description = "Data needed to create the song and save it to the filesystem", diff --git a/src/main.rs b/src/main.rs index 1969bc8..0baf7dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,16 +53,16 @@ pub mod init { use utoipa::OpenApi; use crate::callers::coverart as coverart_caller; - use crate::callers::metadata as metadata_caller; use crate::callers::queue::coverart as coverart_queue_callers; + use crate::callers::queue::metadata as metadata_queue_caller; use crate::callers::queue::song as song_queue_callers; use crate::callers::song as song_caller; use coverart_caller::endpoint as coverart_endpoints; use coverart_caller::response as coverart_responses; use coverart_queue_callers::endpoint as coverart_queue_endpoints; use coverart_queue_callers::response as coverart_queue_responses; - use metadata_caller::endpoint as metadata_endpoints; - use metadata_caller::response as metadata_responses; + use metadata_queue_caller::endpoint as metadata_queue_endpoints; + use metadata_queue_caller::response as metadata_queue_responses; use song_caller::endpoint as song_endpoints; use song_caller::response as song_responses; use song_queue_callers::endpoint as song_queue_endpoints; @@ -123,14 +123,14 @@ pub mod init { song_endpoints::delete_song, coverart_queue_endpoints::queue, coverart_queue_endpoints::link, coverart_queue_endpoints::fetch_coverart_no_data, coverart_queue_endpoints::fetch_coverart_with_data, coverart_endpoints::create_coverart, coverart_queue_endpoints::wipe_data_from_coverart_queue, coverart_endpoints::get_coverart, coverart_endpoints::download_coverart, - metadata_endpoints::queue_metadata, metadata_endpoints::fetch_metadata), + metadata_queue_endpoints::queue_metadata, metadata_queue_endpoints::fetch_metadata), components(schemas(song_queue_callers::response::song_queue::Response, song_queue_callers::response::link_user_id::Response, song_queue_callers::response::fetch_queue_song::Response, song_queue_responses::update_status::Response, song_queue_callers::response::update_song_queue::Response, song_responses::create_metadata::Response, song_queue_callers::response::wipe_data_from_song_queue::Response, song_responses::get_songs::Response, song_responses::delete_song::Response, coverart_queue_responses::queue::Response, coverart_queue_responses::link::Response, coverart_queue_responses::fetch_coverart_no_data::Response, coverart_queue_responses::fetch_coverart_with_data::Response, coverart_responses::create_coverart::Response, coverart_queue_responses::wipe_data_from_coverart_queue::Response, coverart_responses::get_coverart::Response, - metadata_responses::queue_metadata::Response, metadata_responses::fetch_metadata::Response)), + metadata_queue_responses::queue_metadata::Response, metadata_queue_responses::fetch_metadata::Response)), tags( (name = "Icarus API", description = "Web API to manage music") ) @@ -184,14 +184,14 @@ pub mod init { )), ) .route( - crate::callers::endpoints::QUEUEMETADATA, - post(crate::callers::metadata::endpoint::queue_metadata).route_layer( + crate::callers::queue::endpoints::QUEUEMETADATA, + post(crate::callers::queue::metadata::endpoint::queue_metadata).route_layer( axum::middleware::from_fn(crate::auth::auth::), ), ) .route( - crate::callers::endpoints::QUEUEMETADATA, - get(crate::callers::metadata::endpoint::fetch_metadata).route_layer( + crate::callers::queue::endpoints::QUEUEMETADATA, + get(crate::callers::queue::metadata::endpoint::fetch_metadata).route_layer( axum::middleware::from_fn(crate::auth::auth::), ), ) @@ -521,7 +521,11 @@ mod tests { app: &axum::Router, id: &uuid::Uuid, ) -> Result { - let uri = format!("{}?id={}", crate::callers::endpoints::QUEUEMETADATA, id); + let uri = format!( + "{}?id={}", + crate::callers::queue::endpoints::QUEUEMETADATA, + id + ); let req = axum::http::Request::builder() .method(axum::http::Method::GET) @@ -583,7 +587,7 @@ mod tests { let req = axum::http::Request::builder() .method(axum::http::Method::POST) - .uri(crate::callers::endpoints::QUEUEMETADATA) + .uri(crate::callers::queue::endpoints::QUEUEMETADATA) .header(axum::http::header::CONTENT_TYPE, "application/json") .header(axum::http::header::AUTHORIZATION, bearer_auth().await) .body(axum::body::Body::from(payload.to_string())) @@ -796,7 +800,7 @@ mod tests { match queue_song_flow(&app).await { Ok((song_response, user_id)) => { let resp = super::get_resp_data::< - crate::callers::metadata::response::fetch_metadata::Response, + crate::callers::queue::metadata::response::fetch_metadata::Response, >(song_response) .await; assert_eq!(false, resp.data.is_empty(), "Data should not be empty"); @@ -1393,7 +1397,7 @@ mod tests { match sequence_flow::queue_song_flow(&app).await { Ok((response, _user_id)) => { let resp = get_resp_data::< - crate::callers::metadata::response::fetch_metadata::Response, + crate::callers::queue::metadata::response::fetch_metadata::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Data should not be empty"); @@ -1724,7 +1728,7 @@ mod tests { match sequence_flow::queue_song_flow(&app).await { Ok((response, user_id)) => { let resp = get_resp_data::< - crate::callers::metadata::response::fetch_metadata::Response, + crate::callers::queue::metadata::response::fetch_metadata::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Data should not be empty"); @@ -1787,7 +1791,7 @@ mod tests { match sequence_flow::queue_song_flow(&app).await { Ok((response, user_id)) => { let resp = get_resp_data::< - crate::callers::metadata::response::fetch_metadata::Response, + crate::callers::queue::metadata::response::fetch_metadata::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Data should not be empty"); @@ -1880,7 +1884,7 @@ mod tests { match sequence_flow::queue_song_flow(&app).await { Ok((response, user_id)) => { let resp = get_resp_data::< - crate::callers::metadata::response::fetch_metadata::Response, + crate::callers::queue::metadata::response::fetch_metadata::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Data should not be empty"); @@ -1986,7 +1990,7 @@ mod tests { match sequence_flow::queue_song_flow(&app).await { Ok((response, user_id)) => { let resp = get_resp_data::< - crate::callers::metadata::response::fetch_metadata::Response, + crate::callers::queue::metadata::response::fetch_metadata::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Data should not be empty");