Reorganizing metadata queue code
This commit is contained in:
+50
-44
@@ -1,40 +1,43 @@
|
|||||||
// TODO: Explicitly make this module target queueing a song's metadata
|
// TODO: Explicitly make this module target queueing a song's metadata
|
||||||
pub mod request {
|
pub mod request {
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Deserialize, Serialize, sqlx::FromRow)]
|
pub mod queue_metadata {
|
||||||
pub struct Request {
|
use serde::{Deserialize, Serialize};
|
||||||
pub id: uuid::Uuid,
|
|
||||||
pub album: String,
|
|
||||||
pub album_artist: String,
|
|
||||||
pub artist: String,
|
|
||||||
pub disc: i32,
|
|
||||||
pub disc_count: i32,
|
|
||||||
pub duration: i64,
|
|
||||||
pub genre: String,
|
|
||||||
pub title: String,
|
|
||||||
pub track: i32,
|
|
||||||
pub track_count: i32,
|
|
||||||
pub year: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Request {
|
#[derive(Debug, Default, Deserialize, Serialize, sqlx::FromRow)]
|
||||||
pub async fn to_json_value(&self) -> serde_json::Value {
|
pub struct Request {
|
||||||
serde_json::json!(
|
pub song_queue_id: uuid::Uuid,
|
||||||
{
|
pub album: String,
|
||||||
"id": &self.id,
|
pub album_artist: String,
|
||||||
"album": &self.album,
|
pub artist: String,
|
||||||
"album_artist": &self.album_artist,
|
pub disc: i32,
|
||||||
"genre": &self.genre,
|
pub disc_count: i32,
|
||||||
"year": &self.year,
|
pub duration: i64,
|
||||||
"track_count": &self.track_count,
|
pub genre: String,
|
||||||
"disc_count": &self.disc_count,
|
pub title: String,
|
||||||
"title": &self.title,
|
pub track: i32,
|
||||||
"artist": &self.artist,
|
pub track_count: i32,
|
||||||
"disc": &self.disc,
|
pub year: i32,
|
||||||
"track": &self.track,
|
}
|
||||||
"duration": &self.duration,
|
|
||||||
})
|
impl Request {
|
||||||
|
pub async fn to_json_value(&self) -> serde_json::Value {
|
||||||
|
serde_json::json!(
|
||||||
|
{
|
||||||
|
"song_queue_id": &self.song_queue_id,
|
||||||
|
"album": &self.album,
|
||||||
|
"album_artist": &self.album_artist,
|
||||||
|
"genre": &self.genre,
|
||||||
|
"year": &self.year,
|
||||||
|
"track_count": &self.track_count,
|
||||||
|
"disc_count": &self.disc_count,
|
||||||
|
"title": &self.title,
|
||||||
|
"artist": &self.artist,
|
||||||
|
"disc": &self.disc,
|
||||||
|
"track": &self.track,
|
||||||
|
"duration": &self.duration,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +53,15 @@ pub mod request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod response {
|
pub mod response {
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize)]
|
pub mod queue_metadata {
|
||||||
pub struct Response {
|
use serde::{Deserialize, Serialize};
|
||||||
pub message: String,
|
|
||||||
pub data: Vec<uuid::Uuid>,
|
#[derive(Default, Deserialize, Serialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<uuid::Uuid>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod fetch_metadata {
|
pub mod fetch_metadata {
|
||||||
@@ -203,14 +209,14 @@ pub mod endpoint {
|
|||||||
|
|
||||||
pub async fn queue_metadata(
|
pub async fn queue_metadata(
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
Json(payload): Json<super::request::Request>,
|
Json(payload): Json<super::request::queue_metadata::Request>,
|
||||||
) -> (StatusCode, Json<super::response::Response>) {
|
) -> (StatusCode, Json<super::response::queue_metadata::Response>) {
|
||||||
let mut results: Vec<uuid::Uuid> = Vec::new();
|
let mut results: Vec<uuid::Uuid> = Vec::new();
|
||||||
let mut response = super::response::Response::default();
|
let mut response = super::response::queue_metadata::Response::default();
|
||||||
let meta = payload.to_json_value().await;
|
let meta = payload.to_json_value().await;
|
||||||
match super::metadata_queue::insert(&pool, &meta, &payload.id).await {
|
match super::metadata_queue::insert(&pool, &meta, &payload.song_queue_id).await {
|
||||||
Ok(id) => {
|
Ok(metadata_queue_id) => {
|
||||||
results.push(id);
|
results.push(metadata_queue_id);
|
||||||
response.data = results;
|
response.data = results;
|
||||||
response.message = if response.data.is_empty() {
|
response.message = if response.data.is_empty() {
|
||||||
String::from("Error")
|
String::from("Error")
|
||||||
|
|||||||
Reference in New Issue
Block a user