Filling out code

This commit is contained in:
kdeng00
2025-05-23 16:16:43 -04:00
parent 2eaede9f0b
commit 9d68b54c94
+38
View File
@@ -46,8 +46,36 @@ pub mod request {
pub song_queue_id: Option<uuid::Uuid>,
}
}
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<sqlx::PgPool>,
axum::Json(payload): axum::Json<super::request::create_metadata::Request>,
) -> (axum::http::StatusCode, axum::Json<super::response::create_metadata::Response>) {
let mut response = super::response::create_metadata::Response::default();
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))
}
}
}