From 6d4b2decec1afd5f495f008eb4423704dbb974bc Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 24 Oct 2025 21:43:05 -0400 Subject: [PATCH 1/5] tsk-199: Created queue module for queue endpoints --- src/callers/coverart.rs | 378 -------------------------------- src/callers/mod.rs | 1 + src/callers/queue/coverart.rs | 395 ++++++++++++++++++++++++++++++++++ src/callers/queue/mod.rs | 2 + src/main.rs | 23 +- src/repo/queue/coverart.rs | 8 +- 6 files changed, 415 insertions(+), 392 deletions(-) create mode 100644 src/callers/queue/coverart.rs create mode 100644 src/callers/queue/mod.rs diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 06ba3f1..78f0b28 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -1,49 +1,4 @@ -// TODO: Separate queue and coverart endpoints -#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] -pub struct CoverArtQueue { - pub id: uuid::Uuid, - pub file_type: String, - pub song_queue_id: uuid::Uuid, -} - pub mod request { - pub mod queue { - #[derive(utoipa::ToSchema)] - pub struct Request { - /// Filename - pub file: String, - #[schema(rename = "type")] - /// File type. Should be a file and not a value - pub file_type: String, - /// Raw data of the cover art file - pub value: Vec, - } - } - - pub mod link { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] - pub struct Request { - pub coverart_id: uuid::Uuid, - pub song_queue_id: uuid::Uuid, - } - } - - pub mod fetch_coverart_no_data { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] - pub struct Params { - pub id: Option, - pub song_queue_id: Option, - } - } - - pub mod fetch_coverart_with_data { - #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] - pub struct Params { - pub id: Option, - pub song_queue_id: Option, - } - } - pub mod create_coverart { #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Request { @@ -52,13 +7,6 @@ pub mod request { } } - pub mod wipe_data_from_coverart_queue { - #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] - pub struct Request { - pub coverart_queue_id: uuid::Uuid, - } - } - pub mod get_coverart { #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Params { @@ -68,42 +16,6 @@ pub mod request { } pub mod response { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] - pub struct Response { - pub message: String, - pub data: Vec, - } - - pub mod link { - #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] - pub struct Id { - pub coverart_id: uuid::Uuid, - pub song_queue_id: uuid::Uuid, - } - - #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] - pub struct Response { - pub message: String, - pub data: Vec, - } - } - - pub mod fetch_coverart_no_data { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] - pub struct Response { - pub message: String, - pub data: Vec, - } - } - - pub mod fetch_coverart_with_data { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] - pub struct Response { - pub message: String, - pub data: Vec>, - } - } - pub mod create_coverart { #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { @@ -112,14 +24,6 @@ pub mod response { } } - pub mod wipe_data_from_coverart_queue { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] - pub struct Response { - pub message: String, - pub data: Vec, - } - } - pub mod get_coverart { #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { @@ -129,23 +33,6 @@ pub mod response { } } -mod helper { - pub fn is_coverart_file_type_valid(file_type: &String) -> bool { - let valid_file_types = vec![ - String::from(icarus_meta::detection::coverart::constants::JPEG_TYPE), - String::from(icarus_meta::detection::coverart::constants::JPG_TYPE), - String::from(icarus_meta::detection::coverart::constants::PNG_TYPE), - ]; - - for valid_file_type in valid_file_types { - if valid_file_type == *file_type { - return true; - } - } - - false - } -} pub mod endpoint { use axum::response::IntoResponse; @@ -153,226 +40,6 @@ pub mod endpoint { use crate::repo; use crate::repo::queue as repo_queue; - /// Endpoint to queue cover art - #[utoipa::path( - post, - path = super::super::endpoints::QUEUECOVERART, - request_body( - content = super::request::queue::Request, - ), - responses( - (status = 200, description = "Successful", body = super::response::Response), - (status = 400, description = "Error queueing cover art", body = super::response::Response) - ) - )] - pub async fn queue( - axum::Extension(pool): axum::Extension, - mut multipart: axum::extract::Multipart, - ) -> ( - axum::http::StatusCode, - axum::Json, - ) { - let mut response = super::response::Response::default(); - - match multipart.next_field().await { - Ok(Some(field)) => { - let name = field.name().unwrap().to_string(); - let file_name = field.file_name().unwrap().to_string(); - let content_type = field.content_type().unwrap().to_string(); - let data = field.bytes().await.unwrap(); - let raw_data = data.to_vec(); - let file_type = - match icarus_meta::detection::coverart::file_type_from_data(&raw_data) { - Ok(file_type) => file_type, - Err(err) => { - eprintln!("Error: {err:?}"); - response.message = err.to_string(); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - axum::Json(response), - ); - } - }; - - if !super::helper::is_coverart_file_type_valid(&file_type.file_type) { - response.message = format!("CoverArt file type not supported: {file_type:?}"); - ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - axum::Json(response), - ) - } else { - println!( - "Received file '{}' (name = '{}', content-type = '{}', size = {}, file-type = {:?})", - file_name, - name, - content_type, - data.len(), - file_type - ); - - match repo_queue::coverart::insert(&pool, &raw_data, &file_type.file_type).await - { - Ok(id) => { - response.message = String::from("Successful"); - response.data.push(id); - (axum::http::StatusCode::OK, axum::Json(response)) - } - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } - } - } - Ok(None) => (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)), - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } - } - - /// Endpoint to link queued cover art - #[utoipa::path( - post, - path = super::super::endpoints::QUEUECOVERARTLINK, - request_body( - content = super::request::link::Request, - description = "Linking queued cover art to queued song", - content_type = "application/json" - ), - responses( - (status = 200, description = "Queued cover art linked", body = super::response::link::Response), - (status = 400, description = "Linkage failed", body = super::response::link::Response) - ) - )] - pub async fn link( - axum::Extension(pool): axum::Extension, - axum::Json(payload): axum::Json, - ) -> ( - axum::http::StatusCode, - axum::Json, - ) { - let mut response = super::response::link::Response::default(); - let id = payload.coverart_id; - let song_id = payload.song_queue_id; - - match repo_queue::coverart::update(&pool, &id, &song_id).await { - Ok(_o) => { - response.data.push(super::response::link::Id { - song_queue_id: song_id, - coverart_id: id, - }); - - (axum::http::StatusCode::OK, axum::Json(response)) - } - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } - } - - /// Endpoint to fetch cover art details - #[utoipa::path( - get, - path = super::super::endpoints::QUEUECOVERART, - params( - ("id" = uuid::Uuid, Path, description = "Queued cover art Id"), - ("song_queue_id" = uuid::Uuid, Path, description = "Queued song Id") - ), - responses( - (status = 200, description = "Queued song linked", body = super::response::fetch_coverart_no_data::Response), - (status = 400, description = "Linkage failed", body = super::response::fetch_coverart_no_data::Response) - ) - )] - pub async fn fetch_coverart_no_data( - axum::Extension(pool): axum::Extension, - axum::extract::Query(params): axum::extract::Query< - super::request::fetch_coverart_no_data::Params, - >, - ) -> ( - axum::http::StatusCode, - axum::Json, - ) { - let mut response = super::response::fetch_coverart_no_data::Response::default(); - - match params.id { - Some(id) => match repo_queue::coverart::get_coverart_queue_with_id(&pool, &id).await { - Ok(cover_art_queue) => { - response.message = String::from("Successful"); - response.data.push(cover_art_queue); - (axum::http::StatusCode::OK, axum::Json(response)) - } - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - }, - _ => match params.song_queue_id { - Some(song_queue_id) => { - match repo_queue::coverart::get_coverart_queue_with_song_queue_id( - &pool, - &song_queue_id, - ) - .await - { - Ok(cover_art_queue) => { - response.message = String::from("Successful"); - response.data.push(cover_art_queue); - (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("No valid id provided"); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - }, - } - } - - /// Endpoint to fetch the queued cover art data - #[utoipa::path( - get, - path = super::super::endpoints::QUEUECOVERARTDATA, - params(("id" = uuid::Uuid, Path, description = "Queued cover art Id")), - responses( - (status = 200, description = "Queued cover art data", body = Vec), - (status = 400, description = "Error fetching queued cover art data", body = Vec) - ) - )] - pub async fn fetch_coverart_with_data( - axum::Extension(pool): axum::Extension, - axum::extract::Path(id): axum::extract::Path, - ) -> (axum::http::StatusCode, axum::response::Response) { - match repo_queue::coverart::get_coverart_queue_data_with_id(&pool, &id).await { - Ok(data) => { - let bytes = axum::body::Bytes::from(data); - let mut response = bytes.into_response(); - let headers = response.headers_mut(); - // TODO: Address this hard coding for the coverart content type - headers.insert(axum::http::header::CONTENT_TYPE, "image".parse().unwrap()); - // TODO: Make the conent disposition more dynamic - headers.insert( - axum::http::header::CONTENT_DISPOSITION, - format!("attachment; filename=\"{id}.jpg\"") - .parse() - .unwrap(), - ); - - (axum::http::StatusCode::OK, response) - } - Err(_err) => ( - axum::http::StatusCode::BAD_REQUEST, - axum::response::Response::default(), - ), - } - } /// Endpoint to create cover art #[utoipa::path( @@ -455,51 +122,6 @@ pub mod endpoint { } } - /// Endpoint to wipe data from the cover art queue - #[utoipa::path( - patch, - path = super::super::endpoints::QUEUECOVERARTDATAWIPE, - request_body( - content = super::request::wipe_data_from_coverart_queue::Request, - description = "Data required to wipe the data from the cover art queue", - content_type = "application/json" - ), - responses( - (status = 200, description = "Data wiped from cover art queue", body = super::response::wipe_data_from_coverart_queue::Response), - (status = 400, description = "Error wiping the data", body = super::response::wipe_data_from_coverart_queue::Response), - (status = 404, description = "Cover art not found", body = super::response::wipe_data_from_coverart_queue::Response) - ) - )] - pub async fn wipe_data_from_coverart_queue( - axum::Extension(pool): axum::Extension, - axum::Json(payload): axum::Json, - ) -> ( - axum::http::StatusCode, - axum::Json, - ) { - let mut response = super::response::wipe_data_from_coverart_queue::Response::default(); - let coverart_queue_id = payload.coverart_queue_id; - - match repo_queue::coverart::get_coverart_queue_with_id(&pool, &coverart_queue_id).await { - Ok(coverart_queue) => { - match repo_queue::coverart::wipe_data(&pool, &coverart_queue.id).await { - Ok(id) => { - response.message = String::from("Success"); - response.data.push(id); - (axum::http::StatusCode::OK, axum::Json(response)) - } - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } - } - } - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::NOT_FOUND, axum::Json(response)) - } - } - } /// Endpoint to get cover art with criteria #[utoipa::path( diff --git a/src/callers/mod.rs b/src/callers/mod.rs index f19362a..df3666c 100644 --- a/src/callers/mod.rs +++ b/src/callers/mod.rs @@ -1,5 +1,6 @@ pub mod coverart; pub mod metadata; +pub mod queue; pub mod song; pub mod endpoints { diff --git a/src/callers/queue/coverart.rs b/src/callers/queue/coverart.rs new file mode 100644 index 0000000..3166afc --- /dev/null +++ b/src/callers/queue/coverart.rs @@ -0,0 +1,395 @@ +#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] +pub struct CoverArtQueue { + pub id: uuid::Uuid, + pub file_type: String, + pub song_queue_id: uuid::Uuid, +} + +pub mod request { + pub mod queue { + #[derive(utoipa::ToSchema)] + pub struct Request { + /// Filename + pub file: String, + #[schema(rename = "type")] + /// File type. Should be a file and not a value + pub file_type: String, + /// Raw data of the cover art file + pub value: Vec, + } + } + + pub mod link { + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] + pub struct Request { + pub coverart_id: uuid::Uuid, + pub song_queue_id: uuid::Uuid, + } + } + + pub mod fetch_coverart_no_data { + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] + pub struct Params { + pub id: Option, + pub song_queue_id: Option, + } + } + + pub mod fetch_coverart_with_data { + #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] + pub struct Params { + pub id: Option, + pub song_queue_id: Option, + } + } + + pub mod wipe_data_from_coverart_queue { + #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] + pub struct Request { + pub coverart_queue_id: uuid::Uuid, + } + } +} + + +pub mod response { + pub mod queue { + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] + pub struct Response { + pub message: String, + pub data: Vec, + } + } + + pub mod link { + #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] + pub struct Id { + pub coverart_id: uuid::Uuid, + pub song_queue_id: uuid::Uuid, + } + + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] + pub struct Response { + pub message: String, + pub data: Vec, + } + } + + pub mod fetch_coverart_no_data { + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] + pub struct Response { + pub message: String, + pub data: Vec, + } + } + + pub mod fetch_coverart_with_data { + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] + pub struct Response { + pub message: String, + pub data: Vec>, + } + } + + pub mod wipe_data_from_coverart_queue { + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] + pub struct Response { + pub message: String, + pub data: Vec, + } + } +} + + +mod helper { + pub fn is_coverart_file_type_valid(file_type: &String) -> bool { + let valid_file_types = vec![ + String::from(icarus_meta::detection::coverart::constants::JPEG_TYPE), + String::from(icarus_meta::detection::coverart::constants::JPG_TYPE), + String::from(icarus_meta::detection::coverart::constants::PNG_TYPE), + ]; + + for valid_file_type in valid_file_types { + if valid_file_type == *file_type { + return true; + } + } + + false + } +} + + +pub mod endpoint { + use axum::response::IntoResponse; + + use crate::repo::queue as repo; + + + /// Endpoint to queue cover art + #[utoipa::path( + post, + path = super::super::super::endpoints::QUEUECOVERART, + request_body( + content = super::request::queue::Request, + ), + responses( + (status = 200, description = "Successful", body = super::response::queue::Response), + (status = 400, description = "Error queueing cover art", body = super::response::queue::Response) + ) + )] + pub async fn queue( + axum::Extension(pool): axum::Extension, + mut multipart: axum::extract::Multipart, + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { + let mut response = super::response::queue::Response::default(); + + match multipart.next_field().await { + Ok(Some(field)) => { + let name = field.name().unwrap().to_string(); + let file_name = field.file_name().unwrap().to_string(); + let content_type = field.content_type().unwrap().to_string(); + let data = field.bytes().await.unwrap(); + let raw_data = data.to_vec(); + let file_type = + match icarus_meta::detection::coverart::file_type_from_data(&raw_data) { + Ok(file_type) => file_type, + Err(err) => { + eprintln!("Error: {err:?}"); + response.message = err.to_string(); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ); + } + }; + + if !super::helper::is_coverart_file_type_valid(&file_type.file_type) { + response.message = format!("CoverArt file type not supported: {file_type:?}"); + ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + axum::Json(response), + ) + } else { + println!( + "Received file '{}' (name = '{}', content-type = '{}', size = {}, file-type = {:?})", + file_name, + name, + content_type, + data.len(), + file_type + ); + + match repo::coverart::insert(&pool, &raw_data, &file_type.file_type).await + { + Ok(id) => { + response.message = String::from("Successful"); + response.data.push(id); + (axum::http::StatusCode::OK, axum::Json(response)) + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + } + } + Ok(None) => (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)), + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + } + + /// Endpoint to link queued cover art + #[utoipa::path( + post, + path = super::super::super::endpoints::QUEUECOVERARTLINK, + request_body( + content = super::request::link::Request, + description = "Linking queued cover art to queued song", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued cover art linked", body = super::response::link::Response), + (status = 400, description = "Linkage failed", body = super::response::link::Response) + ) + )] + pub async fn link( + axum::Extension(pool): axum::Extension, + axum::Json(payload): axum::Json, + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { + let mut response = super::response::link::Response::default(); + let id = payload.coverart_id; + let song_id = payload.song_queue_id; + + match repo::coverart::update(&pool, &id, &song_id).await { + Ok(_o) => { + response.data.push(super::response::link::Id { + song_queue_id: song_id, + coverart_id: id, + }); + + (axum::http::StatusCode::OK, axum::Json(response)) + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + } + + /// Endpoint to fetch cover art details + #[utoipa::path( + get, + path = super::super::super::endpoints::QUEUECOVERART, + params( + ("id" = uuid::Uuid, Path, description = "Queued cover art Id"), + ("song_queue_id" = uuid::Uuid, Path, description = "Queued song Id") + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::fetch_coverart_no_data::Response), + (status = 400, description = "Linkage failed", body = super::response::fetch_coverart_no_data::Response) + ) + )] + pub async fn fetch_coverart_no_data( + axum::Extension(pool): axum::Extension, + axum::extract::Query(params): axum::extract::Query< + super::request::fetch_coverart_no_data::Params, + >, + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { + let mut response = super::response::fetch_coverart_no_data::Response::default(); + + match params.id { + Some(id) => match repo::coverart::get_coverart_queue_with_id(&pool, &id).await { + Ok(cover_art_queue) => { + response.message = String::from("Successful"); + response.data.push(cover_art_queue); + (axum::http::StatusCode::OK, axum::Json(response)) + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + }, + _ => match params.song_queue_id { + Some(song_queue_id) => { + match repo::coverart::get_coverart_queue_with_song_queue_id( + &pool, + &song_queue_id, + ) + .await + { + Ok(cover_art_queue) => { + response.message = String::from("Successful"); + response.data.push(cover_art_queue); + (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("No valid id provided"); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + }, + } + } + + /// Endpoint to fetch the queued cover art data + #[utoipa::path( + get, + path = super::super::super::endpoints::QUEUECOVERARTDATA, + params(("id" = uuid::Uuid, Path, description = "Queued cover art Id")), + responses( + (status = 200, description = "Queued cover art data", body = Vec), + (status = 400, description = "Error fetching queued cover art data", body = Vec) + ) + )] + pub async fn fetch_coverart_with_data( + axum::Extension(pool): axum::Extension, + axum::extract::Path(id): axum::extract::Path, + ) -> (axum::http::StatusCode, axum::response::Response) { + match repo::coverart::get_coverart_queue_data_with_id(&pool, &id).await { + Ok(data) => { + let bytes = axum::body::Bytes::from(data); + let mut response = bytes.into_response(); + let headers = response.headers_mut(); + // TODO: Address this hard coding for the coverart content type + headers.insert(axum::http::header::CONTENT_TYPE, "image".parse().unwrap()); + // TODO: Make the conent disposition more dynamic + headers.insert( + axum::http::header::CONTENT_DISPOSITION, + format!("attachment; filename=\"{id}.jpg\"") + .parse() + .unwrap(), + ); + + (axum::http::StatusCode::OK, response) + } + Err(_err) => ( + axum::http::StatusCode::BAD_REQUEST, + axum::response::Response::default(), + ), + } + } + + /// Endpoint to wipe data from the cover art queue + #[utoipa::path( + patch, + path = super::super::super::endpoints::QUEUECOVERARTDATAWIPE, + request_body( + content = super::request::wipe_data_from_coverart_queue::Request, + description = "Data required to wipe the data from the cover art queue", + content_type = "application/json" + ), + responses( + (status = 200, description = "Data wiped from cover art queue", body = super::response::wipe_data_from_coverart_queue::Response), + (status = 400, description = "Error wiping the data", body = super::response::wipe_data_from_coverart_queue::Response), + (status = 404, description = "Cover art not found", body = super::response::wipe_data_from_coverart_queue::Response) + ) + )] + pub async fn wipe_data_from_coverart_queue( + axum::Extension(pool): axum::Extension, + axum::Json(payload): axum::Json, + ) -> ( + axum::http::StatusCode, + axum::Json, + ) { + let mut response = super::response::wipe_data_from_coverart_queue::Response::default(); + let coverart_queue_id = payload.coverart_queue_id; + + match repo::coverart::get_coverart_queue_with_id(&pool, &coverart_queue_id).await { + Ok(coverart_queue) => { + match repo::coverart::wipe_data(&pool, &coverart_queue.id).await { + Ok(id) => { + response.message = String::from("Success"); + response.data.push(id); + (axum::http::StatusCode::OK, axum::Json(response)) + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } + } + } + Err(err) => { + response.message = err.to_string(); + (axum::http::StatusCode::NOT_FOUND, axum::Json(response)) + } + } + } +} diff --git a/src/callers/queue/mod.rs b/src/callers/queue/mod.rs new file mode 100644 index 0000000..f76a2ee --- /dev/null +++ b/src/callers/queue/mod.rs @@ -0,0 +1,2 @@ +pub mod coverart; + diff --git a/src/main.rs b/src/main.rs index fdcd5ee..412ab9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,6 +54,7 @@ pub mod init { 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::song as song_caller; use coverart_caller::endpoint as coverart_endpoints; use coverart_caller::response as coverart_responses; @@ -61,6 +62,8 @@ pub mod init { use metadata_caller::response as metadata_responses; use song_caller::endpoint as song_endpoints; use song_caller::response as song_responses; + use coverart_queue_callers::endpoint as coverart_queue_endpoints; + use coverart_queue_callers::response as coverart_queue_responses; mod cors { pub async fn configure_cors() -> tower_http::cors::CorsLayer { @@ -114,16 +117,16 @@ pub mod init { #[openapi( paths(song_endpoints::queue_song, song_endpoints::link_user_id, song_endpoints::fetch_queue_song, song_endpoints::download_flac, song_endpoints::update_song_queue_status, song_endpoints::update_song_queue, song_endpoints::create_metadata, song_endpoints::wipe_data_from_song_queue, song_endpoints::get_songs, song_endpoints::get_all_songs, song_endpoints::stream_song, song_endpoints::download_song, - song_endpoints::delete_song, coverart_endpoints::queue, coverart_endpoints::link, coverart_endpoints::fetch_coverart_no_data, - coverart_endpoints::fetch_coverart_with_data, coverart_endpoints::create_coverart, coverart_endpoints::wipe_data_from_coverart_queue, + 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), components(schemas(song_responses::Response, song_responses::link_user_id::Response, song_responses::fetch_queue_song::Response, song_responses::update_status::Response, song_responses::update_song_queue::Response, song_responses::create_metadata::Response, song_responses::wipe_data_from_song_queue::Response, song_responses::get_songs::Response, song_responses::delete_song::Response, - coverart_responses::Response, coverart_responses::link::Response, coverart_responses::fetch_coverart_no_data::Response, - coverart_responses::fetch_coverart_with_data::Response, coverart_responses::create_coverart::Response, - coverart_responses::wipe_data_from_coverart_queue::Response, coverart_responses::get_coverart::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)), tags( (name = "Icarus API", description = "Web API to manage music") @@ -190,31 +193,31 @@ pub mod init { ) .route( crate::callers::endpoints::QUEUECOVERART, - post(crate::callers::coverart::endpoint::queue).route_layer( + post(crate::callers::queue::coverart::endpoint::queue).route_layer( axum::middleware::from_fn(crate::auth::auth::), ), ) .route( crate::callers::endpoints::QUEUECOVERARTDATA, - get(crate::callers::coverart::endpoint::fetch_coverart_with_data).route_layer( + get(crate::callers::queue::coverart::endpoint::fetch_coverart_with_data).route_layer( axum::middleware::from_fn(crate::auth::auth::), ), ) .route( crate::callers::endpoints::QUEUECOVERART, - get(crate::callers::coverart::endpoint::fetch_coverart_no_data).route_layer( + get(crate::callers::queue::coverart::endpoint::fetch_coverart_no_data).route_layer( axum::middleware::from_fn(crate::auth::auth::), ), ) .route( crate::callers::endpoints::QUEUECOVERARTLINK, - patch(crate::callers::coverart::endpoint::link).route_layer( + patch(crate::callers::queue::coverart::endpoint::link).route_layer( axum::middleware::from_fn(crate::auth::auth::), ), ) .route( crate::callers::endpoints::QUEUECOVERARTDATAWIPE, - patch(crate::callers::coverart::endpoint::wipe_data_from_coverart_queue) + patch(crate::callers::queue::coverart::endpoint::wipe_data_from_coverart_queue) .route_layer(axum::middleware::from_fn( crate::auth::auth::, )), diff --git a/src/repo/queue/coverart.rs b/src/repo/queue/coverart.rs index ed1349b..d224562 100644 --- a/src/repo/queue/coverart.rs +++ b/src/repo/queue/coverart.rs @@ -54,7 +54,7 @@ pub async fn update( pub async fn get_coverart_queue_with_id( pool: &sqlx::PgPool, id: &uuid::Uuid, -) -> Result { +) -> Result { let result = sqlx::query( r#" SELECT id, file_type, song_queue_id FROM "coverartQueue" WHERE id = $1; @@ -68,7 +68,7 @@ pub async fn get_coverart_queue_with_id( }); match result { - Ok(row) => Ok(crate::callers::coverart::CoverArtQueue { + Ok(row) => Ok(crate::callers::queue::coverart::CoverArtQueue { id: row .try_get("id") .map_err(|_e| sqlx::Error::RowNotFound) @@ -89,7 +89,7 @@ pub async fn get_coverart_queue_with_id( pub async fn get_coverart_queue_with_song_queue_id( pool: &sqlx::PgPool, song_queue_id: &uuid::Uuid, -) -> Result { +) -> Result { let result = sqlx::query( r#" SELECT id, file_type, song_queue_id FROM "coverartQueue" WHERE song_queue_id = $1; @@ -103,7 +103,7 @@ pub async fn get_coverart_queue_with_song_queue_id( }); match result { - Ok(row) => Ok(crate::callers::coverart::CoverArtQueue { + Ok(row) => Ok(crate::callers::queue::coverart::CoverArtQueue { id: row .try_get("id") .map_err(|_e| sqlx::Error::RowNotFound) -- 2.47.3 From bcee2057b7bcd4d5e802295e806c535131d18429 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 24 Oct 2025 21:43:30 -0400 Subject: [PATCH 2/5] tsk-199: Code formatting --- src/callers/coverart.rs | 3 --- src/callers/queue/coverart.rs | 39 ++++++++++++++--------------------- src/callers/queue/mod.rs | 1 - src/main.rs | 11 +++++----- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 78f0b28..82de0ff 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -33,14 +33,12 @@ pub mod response { } } - pub mod endpoint { use axum::response::IntoResponse; use crate::repo; use crate::repo::queue as repo_queue; - /// Endpoint to create cover art #[utoipa::path( post, @@ -122,7 +120,6 @@ pub mod endpoint { } } - /// Endpoint to get cover art with criteria #[utoipa::path( get, diff --git a/src/callers/queue/coverart.rs b/src/callers/queue/coverart.rs index 3166afc..16ed258 100644 --- a/src/callers/queue/coverart.rs +++ b/src/callers/queue/coverart.rs @@ -51,7 +51,6 @@ pub mod request { } } - pub mod response { pub mod queue { #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] @@ -100,7 +99,6 @@ pub mod response { } } - mod helper { pub fn is_coverart_file_type_valid(file_type: &String) -> bool { let valid_file_types = vec![ @@ -119,13 +117,11 @@ mod helper { } } - pub mod endpoint { use axum::response::IntoResponse; use crate::repo::queue as repo; - /// Endpoint to queue cover art #[utoipa::path( post, @@ -183,8 +179,7 @@ pub mod endpoint { file_type ); - match repo::coverart::insert(&pool, &raw_data, &file_type.file_type).await - { + match repo::coverart::insert(&pool, &raw_data, &file_type.file_type).await { Ok(id) => { response.message = String::from("Successful"); response.data.push(id); @@ -283,24 +278,22 @@ pub mod endpoint { } }, _ => match params.song_queue_id { - Some(song_queue_id) => { - match repo::coverart::get_coverart_queue_with_song_queue_id( - &pool, - &song_queue_id, - ) - .await - { - Ok(cover_art_queue) => { - response.message = String::from("Successful"); - response.data.push(cover_art_queue); - (axum::http::StatusCode::OK, axum::Json(response)) - } - Err(err) => { - response.message = err.to_string(); - (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) - } + Some(song_queue_id) => match repo::coverart::get_coverart_queue_with_song_queue_id( + &pool, + &song_queue_id, + ) + .await + { + Ok(cover_art_queue) => { + response.message = String::from("Successful"); + response.data.push(cover_art_queue); + (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("No valid id provided"); (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) diff --git a/src/callers/queue/mod.rs b/src/callers/queue/mod.rs index f76a2ee..165fc86 100644 --- a/src/callers/queue/mod.rs +++ b/src/callers/queue/mod.rs @@ -1,2 +1 @@ pub mod coverart; - diff --git a/src/main.rs b/src/main.rs index 412ab9f..b011398 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,12 +58,12 @@ pub mod init { 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 song_caller::endpoint as song_endpoints; use song_caller::response as song_responses; - use coverart_queue_callers::endpoint as coverart_queue_endpoints; - use coverart_queue_callers::response as coverart_queue_responses; mod cors { pub async fn configure_cors() -> tower_http::cors::CorsLayer { @@ -199,9 +199,10 @@ pub mod init { ) .route( crate::callers::endpoints::QUEUECOVERARTDATA, - get(crate::callers::queue::coverart::endpoint::fetch_coverart_with_data).route_layer( - axum::middleware::from_fn(crate::auth::auth::), - ), + get(crate::callers::queue::coverart::endpoint::fetch_coverart_with_data) + .route_layer(axum::middleware::from_fn( + crate::auth::auth::, + )), ) .route( crate::callers::endpoints::QUEUECOVERART, -- 2.47.3 From ee6681f6a733c7c97771aee1ea268b4333fe676b Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 25 Oct 2025 21:06:24 -0400 Subject: [PATCH 3/5] tsk-199: Test fixes --- src/main.rs | 65 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/main.rs b/src/main.rs index b011398..18a10f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -747,11 +747,10 @@ mod tests { ) -> Result { match super::upload_coverart_queue_req(&app).await { Ok(response) => { - let resp = - super::get_resp_data::( - response, - ) - .await; + let resp = super::get_resp_data::< + crate::callers::queue::coverart::response::queue::Response, + >(response) + .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); let coverart_id = resp.data[0]; assert_eq!(false, coverart_id.is_nil(), "Should not be empty"); @@ -765,7 +764,7 @@ mod tests { { Ok(response) => { let resp = super::get_resp_data::< - crate::callers::coverart::response::link::Response, + crate::callers::queue::coverart::response::link::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); @@ -1027,7 +1026,7 @@ mod tests { match sequence_flow::queue_song_and_coverart_flow(&app).await { Ok((resp_one, song_queue_id)) => { let resp = get_resp_data::< - crate::callers::coverart::response::fetch_coverart_no_data::Response, + crate::callers::queue::coverart::response::fetch_coverart_no_data::Response, >(resp_one) .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); @@ -1260,7 +1259,7 @@ mod tests { match sequence_flow::queue_song_and_coverart_flow(&app).await { Ok((resp_one, song_queue_id)) => { let resp = get_resp_data::< - crate::callers::coverart::response::fetch_coverart_no_data::Response, + crate::callers::queue::coverart::response::fetch_coverart_no_data::Response, >(resp_one) .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); @@ -1400,8 +1399,10 @@ mod tests { // Send request match upload_coverart_queue_req(&app).await { Ok(response) => { - let resp = - get_resp_data::(response).await; + let resp = get_resp_data::< + crate::callers::queue::coverart::response::queue::Response, + >(response) + .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); let id = resp.data[0]; assert_eq!(false, id.is_nil(), "Should not be empty"); @@ -1435,8 +1436,10 @@ mod tests { match song_queue_req(&app).await { Ok(response) => { - let resp = - get_resp_data::(response).await; + let resp = get_resp_data::< + crate::callers::queue::coverart::response::queue::Response, + >(response) + .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); let song_queue_id = resp.data[0]; assert_eq!(false, song_queue_id.is_nil(), "Should not be empty"); @@ -1444,9 +1447,10 @@ mod tests { // Send request match upload_coverart_queue_req(&app).await { Ok(response) => { - let resp = - get_resp_data::(response) - .await; + let resp = get_resp_data::< + crate::callers::queue::coverart::response::queue::Response, + >(response) + .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); let coverart_id = resp.data[0]; assert_eq!(false, coverart_id.is_nil(), "Should not be empty"); @@ -1456,7 +1460,7 @@ mod tests { { Ok(response) => { let resp = get_resp_data::< - crate::callers::coverart::response::link::Response, + crate::callers::queue::coverart::response::link::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); @@ -1509,8 +1513,10 @@ mod tests { match song_queue_req(&app).await { Ok(response) => { - let resp = - get_resp_data::(response).await; + let resp = get_resp_data::< + crate::callers::queue::coverart::response::queue::Response, + >(response) + .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); let song_queue_id = resp.data[0]; assert_eq!(false, song_queue_id.is_nil(), "Should not be empty"); @@ -1518,7 +1524,7 @@ mod tests { match sequence_flow::queue_coverart_flow(&app, &song_queue_id).await { Ok(response) => { let resp = get_resp_data::< - crate::callers::coverart::response::fetch_coverart_no_data::Response, + crate::callers::queue::coverart::response::fetch_coverart_no_data::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); @@ -1557,8 +1563,10 @@ mod tests { match song_queue_req(&app).await { Ok(response) => { - let resp = - get_resp_data::(response).await; + let resp = get_resp_data::< + crate::callers::queue::coverart::response::queue::Response, + >(response) + .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); let song_queue_id = resp.data[0]; assert_eq!(false, song_queue_id.is_nil(), "Should not be empty"); @@ -1566,9 +1574,10 @@ mod tests { // Send request match upload_coverart_queue_req(&app).await { Ok(response) => { - let resp = - get_resp_data::(response) - .await; + let resp = get_resp_data::< + crate::callers::queue::coverart::response::queue::Response, + >(response) + .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); let coverart_id = resp.data[0]; assert_eq!(false, coverart_id.is_nil(), "Should not be empty"); @@ -1578,7 +1587,7 @@ mod tests { { Ok(response) => { let resp = get_resp_data::< - crate::callers::coverart::response::link::Response, + crate::callers::queue::coverart::response::link::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); @@ -1778,7 +1787,7 @@ mod tests { match sequence_flow::queue_coverart_flow(&app, &song_queue_id).await { Ok(response) => { let resp = get_resp_data::< - crate::callers::coverart::response::fetch_coverart_no_data::Response, + crate::callers::queue::coverart::response::fetch_coverart_no_data::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); @@ -1979,7 +1988,7 @@ mod tests { match sequence_flow::queue_coverart_flow(&app, &song_queue_id).await { Ok(response) => { let resp = get_resp_data::< - crate::callers::coverart::response::fetch_coverart_no_data::Response, + crate::callers::queue::coverart::response::fetch_coverart_no_data::Response, >(response) .await; assert_eq!(false, resp.data.is_empty(), "Should not be empty"); @@ -2011,7 +2020,7 @@ mod tests { { Ok(response) => { let resp = get_resp_data::< - crate::callers::coverart::response::wipe_data_from_coverart_queue::Response, + crate::callers::queue::coverart::response::wipe_data_from_coverart_queue::Response, >(response) .await; assert_eq!( -- 2.47.3 From f6959bc4d7d7887501af7338876685167132bb73 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 25 Oct 2025 21:07:56 -0400 Subject: [PATCH 4/5] tsk-199: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f4c243c..aec40d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -834,7 +834,7 @@ dependencies = [ [[package]] name = "icarus" -version = "0.3.4" +version = "0.3.5" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index 12f5349..c8a826a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus" -version = "0.3.4" +version = "0.3.5" edition = "2024" rust-version = "1.90" -- 2.47.3 From 0e898d994037480b7ceb2f7bf6a1a242d925b2f1 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 25 Oct 2025 21:09:31 -0400 Subject: [PATCH 5/5] tsk-199: Updated readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9e64c45..eda5ae1 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ Web API for the Icarus project. ### Requires -`icarus_auth` +v0.6.5 -`songparser` +v0.4.8 +`icarus_auth` v0.6.x +`songparser` v0.4.x ### Compatible with -`icarus-dm` v0.8.4 +`icarus-dm` v0.8.x ## Getting Started -- 2.47.3