Reorganizing code

This commit is contained in:
kdeng00
2025-05-23 16:22:19 -04:00
parent 246e6510c1
commit ec1dacf347
2 changed files with 50 additions and 53 deletions
-53
View File
@@ -46,36 +46,8 @@ 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: i32,
}
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};
@@ -94,13 +66,6 @@ pub mod response {
pub data: Vec<crate::callers::metadata::metadata_queue::MetadataQueue>,
}
}
pub mod create_metadata {
#[derive(Default, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
}
}
}
pub mod metadata_queue {
@@ -232,9 +197,6 @@ pub mod metadata_queue {
}
}
pub mod metadata {
}
pub mod endpoint {
use axum::{Json, http::StatusCode};
@@ -309,19 +271,4 @@ 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))
}
}
}
+50
View File
@@ -13,6 +13,32 @@ pub mod request {
pub status: String,
}
}
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: i32,
}
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
}
}
}
}
pub mod response {
@@ -55,8 +81,17 @@ pub mod response {
pub data: Vec<Vec<u8>>,
}
}
pub mod create_metadata {
#[derive(Default, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
}
}
}
// TODO: Might make a distinction between year and date in a song's tag at some point
pub mod status {
pub const PENDING: &str = "pending";
pub const PROCESSING: &str = "processing";
@@ -456,4 +491,19 @@ pub mod endpoint {
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
}
}
// 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))
}
}
}