From 9d68b54c94095dc7bc94647d9e5af5b03b8d519a Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 23 May 2025 16:16:43 -0400 Subject: [PATCH] Filling out code --- src/callers/metadata.rs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/callers/metadata.rs b/src/callers/metadata.rs index 841a4f5..3265831 100644 --- a/src/callers/metadata.rs +++ b/src/callers/metadata.rs @@ -46,8 +46,36 @@ pub mod request { pub song_queue_id: Option, } } + + pub mod create_metadata { + #[derive(Debug, serde::Deserialize, serde::Serialize)] + pub struct Request { + pub title: String, + pub artist: String, + pub album_artist: String, + pub album: String, + pub genre: String, + pub date: String, + pub track: i32, + pub disc: i32, + pub track_count: i32, + pub disc_count: i32, + pub duration: i64, + } + + impl Request { + pub fn is_valid(&self) -> bool { + !self.title.is_empty() || !self.artist.is_empty() || !self.album_artist.is_empty() + || !self.album.is_empty() || !self.genre.is_empty() || !self.date.is_empty() + || self.track > 0 || self.disc > 0 || self.track_count > 0 || self.disc_count > 0 + || self.duration > 0 + } + } + } } +// TODO: Might make a distinction between year and date in a song's tag at some point + pub mod response { use serde::{Deserialize, Serialize}; @@ -204,6 +232,9 @@ pub mod metadata_queue { } } +pub mod metadata { +} + pub mod endpoint { use axum::{Json, http::StatusCode}; @@ -281,9 +312,16 @@ pub mod endpoint { // TODO: Implement pub async fn create_metadata( + axum::Extension(pool): axum::Extension, + axum::Json(payload): axum::Json, ) -> (axum::http::StatusCode, axum::Json) { let mut response = super::response::create_metadata::Response::default(); - (axum::http::StatusCode::OK, axum::Json(response)) + if payload.is_valid() { + (axum::http::StatusCode::OK, axum::Json(response)) + } else { + response.message = String::from("Request body is not valid"); + (axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) + } } }