From e9193c03757dfb40f4442b191e18b599533e0db9 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 13:03:42 -0400 Subject: [PATCH 1/6] tsk-194: Moving metadata module --- src/callers/mod.rs | 3 --- src/callers/{ => queue}/metadata.rs | 37 +++++++++++------------------ src/callers/queue/mod.rs | 2 ++ 3 files changed, 16 insertions(+), 26 deletions(-) rename src/callers/{ => queue}/metadata.rs (82%) 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..0ba714c 100644 --- a/src/callers/metadata.rs +++ b/src/callers/queue/metadata.rs @@ -1,9 +1,6 @@ -// 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 +56,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 +64,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 +74,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 +92,8 @@ 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 +104,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 +132,7 @@ 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 +143,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 +159,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"; -- 2.47.3 From 7ebf875624565bb571790c5f003de3a83cb10f2a Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 13:09:11 -0400 Subject: [PATCH 2/6] tsk-194: Build fix --- src/callers/song.rs | 3 ++- src/main.rs | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) 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..ebbd992 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,7 @@ pub mod init { use utoipa::OpenApi; use crate::callers::coverart as coverart_caller; - use crate::callers::metadata as metadata_caller; + use crate::callers::queue::metadata as metadata_caller; use crate::callers::queue::coverart as coverart_queue_callers; use crate::callers::queue::song as song_queue_callers; use crate::callers::song as song_caller; @@ -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::), ), ) -- 2.47.3 From ae21e74acaa2d62eb50d3cbbf2c302e9ba38ffd3 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 13:11:34 -0400 Subject: [PATCH 3/6] tsk-194: Name changes --- src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index ebbd992..bd04172 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,7 @@ pub mod init { use utoipa::OpenApi; use crate::callers::coverart as coverart_caller; - use crate::callers::queue::metadata as metadata_caller; + use crate::callers::queue::metadata as metadata_queue_caller; use crate::callers::queue::coverart as coverart_queue_callers; use crate::callers::queue::song as song_queue_callers; use crate::callers::song as song_caller; @@ -61,8 +61,8 @@ pub mod init { 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") ) -- 2.47.3 From 90d27e76d90f070013800713d5bb8f08719396e8 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 13:11:49 -0400 Subject: [PATCH 4/6] tsk-194: Code formatting --- src/callers/queue/metadata.rs | 14 +++++++++++--- src/main.rs | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/callers/queue/metadata.rs b/src/callers/queue/metadata.rs index 0ba714c..aedd4c1 100644 --- a/src/callers/queue/metadata.rs +++ b/src/callers/queue/metadata.rs @@ -1,6 +1,8 @@ pub mod request { pub mod queue_metadata { - #[derive(Debug, Default, serde::Deserialize, serde::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, @@ -93,7 +95,10 @@ pub mod endpoint { pub async fn queue_metadata( axum::Extension(pool): axum::Extension, axum::Json(payload): axum::Json, - ) -> (axum::http::StatusCode, 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; @@ -132,7 +137,10 @@ pub mod endpoint { pub async fn fetch_metadata( axum::Extension(pool): axum::Extension, axum::extract::Query(params): axum::extract::Query, - ) -> (axum::http::StatusCode, axum::Json) { + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { let mut response = super::response::fetch_metadata::Response::default(); match params.id { diff --git a/src/main.rs b/src/main.rs index bd04172..2ca7b58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,8 +53,8 @@ pub mod init { use utoipa::OpenApi; use crate::callers::coverart as coverart_caller; - use crate::callers::queue::metadata as metadata_queue_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; -- 2.47.3 From 5152a8543585ec17cbacb68ffc0c91cd23ca2b73 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 13:12:15 -0400 Subject: [PATCH 5/6] tsk-194: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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" -- 2.47.3 From 1ec0dfbebb36548ed004812391db0fa64b61ccf7 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 27 Oct 2025 13:20:34 -0400 Subject: [PATCH 6/6] tsk-194: Test fixes --- src/main.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2ca7b58..0baf7dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); -- 2.47.3