Reorganizing code
This commit is contained in:
@@ -46,36 +46,8 @@ pub mod request {
|
|||||||
pub song_queue_id: Option<uuid::Uuid>,
|
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 {
|
pub mod response {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -94,13 +66,6 @@ pub mod response {
|
|||||||
pub data: Vec<crate::callers::metadata::metadata_queue::MetadataQueue>,
|
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 {
|
pub mod metadata_queue {
|
||||||
@@ -232,9 +197,6 @@ pub mod metadata_queue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod metadata {
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod endpoint {
|
pub mod endpoint {
|
||||||
use axum::{Json, http::StatusCode};
|
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,32 @@ pub mod request {
|
|||||||
pub status: String,
|
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 {
|
pub mod response {
|
||||||
@@ -55,7 +81,16 @@ pub mod response {
|
|||||||
pub data: Vec<Vec<u8>>,
|
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 mod status {
|
||||||
pub const PENDING: &str = "pending";
|
pub const PENDING: &str = "pending";
|
||||||
@@ -456,4 +491,19 @@ pub mod endpoint {
|
|||||||
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
(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))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user