From 594410cb12919e85063bc046bb5dae706eced6b7 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 22 Aug 2025 15:53:29 -0400 Subject: [PATCH] tsk-170: Saving changes --- src/callers/coverart.rs | 104 +++++++++++++++++++++++ src/callers/metadata.rs | 26 ++++++ src/callers/song.rs | 183 ++++++++++++++++++++++++++++++++++++---- src/main.rs | 6 +- 4 files changed, 302 insertions(+), 17 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index a2b2aa0..7b1c8aa 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -465,6 +465,19 @@ pub mod endpoint { use axum::response::IntoResponse; + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn queue( axum::Extension(pool): axum::Extension, mut multipart: axum::extract::Multipart, @@ -510,6 +523,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn link( axum::Extension(pool): axum::Extension, axum::Json(payload): axum::Json, @@ -537,6 +563,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn fetch_coverart_no_data( axum::Extension(pool): axum::Extension, axum::extract::Query(params): axum::extract::Query< @@ -584,6 +623,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn fetch_coverart_with_data( axum::Extension(pool): axum::Extension, axum::extract::Path(id): axum::extract::Path, @@ -612,6 +664,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn create_coverart( axum::Extension(pool): axum::Extension, axum::Json(payload): axum::Json, @@ -672,6 +737,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn wipe_data_from_coverart_queue( axum::Extension(pool): axum::Extension, axum::Json(payload): axum::Json, @@ -701,6 +779,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn get_coverart( axum::Extension(pool): axum::Extension, axum::extract::Query(params): axum::extract::Query, @@ -729,6 +820,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn download_coverart( axum::Extension(pool): axum::Extension, axum::extract::Path(id): axum::extract::Path, diff --git a/src/callers/metadata.rs b/src/callers/metadata.rs index 6825fbd..20d9e7b 100644 --- a/src/callers/metadata.rs +++ b/src/callers/metadata.rs @@ -207,6 +207,19 @@ pub mod metadata_queue { pub mod endpoint { use axum::{Json, http::StatusCode}; + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn queue_metadata( axum::Extension(pool): axum::Extension, Json(payload): Json, @@ -233,6 +246,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn fetch_metadata( axum::Extension(pool): axum::Extension, axum::extract::Query(params): axum::extract::Query, diff --git a/src/callers/song.rs b/src/callers/song.rs index b704d9a..57b19e6 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -21,7 +21,7 @@ pub mod request { } pub mod update_status { - #[derive(Default, serde::Deserialize, serde::Serialize)] + #[derive(Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Request { pub id: uuid::Uuid, pub status: String, @@ -29,7 +29,7 @@ pub mod request { } pub mod create_metadata { - #[derive(Debug, serde::Deserialize, serde::Serialize)] + #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Request { pub title: String, pub artist: String, @@ -92,14 +92,14 @@ pub mod request { } pub mod wipe_data_from_song_queue { - #[derive(Debug, serde::Deserialize, serde::Serialize)] + #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Request { pub song_queue_id: uuid::Uuid, } } pub mod link_user_id { - #[derive(Debug, serde::Deserialize, serde::Serialize)] + #[derive(Debug, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Request { pub song_queue_id: uuid::Uuid, pub user_id: uuid::Uuid, @@ -107,7 +107,7 @@ pub mod request { } pub mod get_songs { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Params { pub id: Option, } @@ -128,7 +128,7 @@ pub mod response { pub mod fetch_queue_song { use serde::{Deserialize, Serialize}; - #[derive(Default, Deserialize, Serialize)] + #[derive(Default, Deserialize, Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, pub data: Vec, @@ -136,7 +136,7 @@ pub mod response { } pub mod update_status { - #[derive(serde::Deserialize, serde::Serialize)] + #[derive(serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct ChangedStatus { pub old_status: String, pub new_status: String, @@ -150,7 +150,7 @@ pub mod response { } pub mod update_song_queue { - #[derive(Default, serde::Deserialize, serde::Serialize)] + #[derive(Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, pub data: Vec, @@ -158,7 +158,7 @@ pub mod response { } pub mod create_metadata { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, pub data: Vec, @@ -166,7 +166,7 @@ pub mod response { } pub mod wipe_data_from_song_queue { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, pub data: Vec, @@ -174,7 +174,7 @@ pub mod response { } pub mod link_user_id { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, pub data: Vec, @@ -182,7 +182,7 @@ pub mod response { } pub mod get_songs { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct Response { pub message: String, pub data: Vec, @@ -190,7 +190,7 @@ pub mod response { } pub mod delete_song { - #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] + #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] pub struct SongAndCoverArt { pub song: icarus_models::song::Song, pub coverart: icarus_models::coverart::CoverArt, @@ -576,7 +576,8 @@ mod song_queue { pub id: uuid::Uuid, } - #[derive(Debug, serde::Deserialize, serde::Serialize, sqlx::FromRow)] + // TODO: Move this somewhere else at some point + #[derive(Debug, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema)] pub struct SongQueue { pub id: uuid::Uuid, pub filename: String, @@ -880,7 +881,7 @@ pub mod endpoint { /// Endpoint to queue a song. Starts the process and places the song in a queue #[utoipa::path( post, - path = "/song/queue", + path = "/api/v2/song/queue", request_body( content = super::request::song_queue::SongQueueRequest, description = "Multipart form data for uploading song", @@ -938,6 +939,20 @@ pub mod endpoint { (StatusCode::OK, Json(response)) } + /// Endpoint to link a user id to a queued song + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn link_user_id( axum::Extension(pool): axum::Extension, axum::Json(payload): axum::Json, @@ -969,6 +984,14 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = super::super::endpoints::NEXTQUEUESONG, + responses( + (status = 200, description = "Queued song is present and available", body = super::response::fetch_queue_song::Response), + (status = 400, description = "Linkage failed", body = super::response::fetch_queue_song::Response) + ) + )] pub async fn fetch_queue_song( axum::Extension(pool): axum::Extension, ) -> ( @@ -991,6 +1014,19 @@ pub mod endpoint { } // TODO: Rename + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn download_flac( axum::Extension(pool): axum::Extension, axum::extract::Path(id): axum::extract::Path, @@ -1019,6 +1055,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn update_song_queue_status( axum::Extension(pool): axum::Extension, axum::Json(payload): axum::Json, @@ -1071,6 +1120,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn update_song_queue( axum::extract::Path(id): axum::extract::Path, axum::Extension(pool): axum::Extension, @@ -1117,6 +1179,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn create_metadata( axum::Extension(pool): axum::Extension, axum::Json(payload): axum::Json, @@ -1200,6 +1275,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn wipe_data_from_song_queue( axum::Extension(pool): axum::Extension, axum::Json(payload): axum::Json, @@ -1230,6 +1318,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn get_songs( axum::Extension(pool): axum::Extension, axum::extract::Query(params): axum::extract::Query, @@ -1258,6 +1359,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn get_all_songs( axum::Extension(pool): axum::Extension, ) -> ( @@ -1279,6 +1393,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn stream_song( axum::Extension(pool): axum::Extension, axum::extract::Path(id): axum::extract::Path, @@ -1326,6 +1453,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn download_song( axum::Extension(pool): axum::Extension, axum::extract::Path(id): axum::extract::Path, @@ -1361,6 +1501,19 @@ pub mod endpoint { } } + #[utoipa::path( + post, + path = "/api/v2/song/queue/link", + request_body( + content = super::request::link_user_id::Request, + description = "User Id and queued song id", + content_type = "application/json" + ), + responses( + (status = 200, description = "Queued song linked", body = super::response::link_user_id::Response), + (status = 400, description = "Linkage failed", body = super::response::link_user_id::Response) + ) + )] pub async fn delete_song( axum::Extension(pool): axum::Extension, axum::extract::Path(id): axum::extract::Path, diff --git a/src/main.rs b/src/main.rs index f2fce76..008aa4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,10 +55,12 @@ pub mod init { header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE}, }; + use crate::callers::song as song_caller; + #[derive(utoipa::OpenApi)] #[openapi( - paths(crate::callers::song::endpoint::queue_song), - components(schemas(crate::callers::song::response::Response)), + paths(song_caller::endpoint::queue_song, song_caller::endpoint::link_user_id), + components(schemas(song_caller::response::Response, song_caller::response::link_user_id::Response)), tags( (name = "queue song", description = "Start process to upload song by queueing the song") )