Reorganizing metadata queue code (#144)
* Reorganizing metadata queue code * Function name change * Test payload changes * function parameter name change
This commit was merged in pull request #144.
This commit is contained in:
+14
-8
@@ -1,10 +1,12 @@
|
|||||||
// 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 {
|
||||||
|
|
||||||
|
pub mod queue_metadata {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Default, Deserialize, Serialize, sqlx::FromRow)]
|
#[derive(Debug, Default, Deserialize, Serialize, sqlx::FromRow)]
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
pub id: uuid::Uuid,
|
pub song_queue_id: uuid::Uuid,
|
||||||
pub album: String,
|
pub album: String,
|
||||||
pub album_artist: String,
|
pub album_artist: String,
|
||||||
pub artist: String,
|
pub artist: String,
|
||||||
@@ -22,7 +24,7 @@ pub mod request {
|
|||||||
pub async fn to_json_value(&self) -> serde_json::Value {
|
pub async fn to_json_value(&self) -> serde_json::Value {
|
||||||
serde_json::json!(
|
serde_json::json!(
|
||||||
{
|
{
|
||||||
"id": &self.id,
|
"song_queue_id": &self.song_queue_id,
|
||||||
"album": &self.album,
|
"album": &self.album,
|
||||||
"album_artist": &self.album_artist,
|
"album_artist": &self.album_artist,
|
||||||
"genre": &self.genre,
|
"genre": &self.genre,
|
||||||
@@ -37,6 +39,7 @@ pub mod request {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod fetch_metadata {
|
pub mod fetch_metadata {
|
||||||
#[derive(
|
#[derive(
|
||||||
@@ -50,6 +53,8 @@ pub mod request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod response {
|
pub mod response {
|
||||||
|
|
||||||
|
pub mod queue_metadata {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Default, Deserialize, Serialize)]
|
#[derive(Default, Deserialize, Serialize)]
|
||||||
@@ -57,6 +62,7 @@ pub mod response {
|
|||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<uuid::Uuid>,
|
pub data: Vec<uuid::Uuid>,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub mod fetch_metadata {
|
pub mod fetch_metadata {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -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")
|
||||||
|
|||||||
+6
-4
@@ -325,9 +325,9 @@ mod tests {
|
|||||||
|
|
||||||
async fn queue_metadata_req(
|
async fn queue_metadata_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||||
let payload = payload_data(&id).await;
|
let payload = payload_data::queue_metadata_payload_data(&song_queue_id).await;
|
||||||
|
|
||||||
let req = axum::http::Request::builder()
|
let req = axum::http::Request::builder()
|
||||||
.method(axum::http::Method::POST)
|
.method(axum::http::Method::POST)
|
||||||
@@ -600,10 +600,11 @@ mod tests {
|
|||||||
serde_json::from_slice(&body).unwrap()
|
serde_json::from_slice(&body).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn payload_data(id: &uuid::Uuid) -> serde_json::Value {
|
pub mod payload_data {
|
||||||
|
pub async fn queue_metadata_payload_data(song_queue_id: &uuid::Uuid) -> serde_json::Value {
|
||||||
serde_json::json!(
|
serde_json::json!(
|
||||||
{
|
{
|
||||||
"id": id,
|
"song_queue_id": song_queue_id,
|
||||||
"album" : "Machine Gun: The FillMore East First Show",
|
"album" : "Machine Gun: The FillMore East First Show",
|
||||||
"album_artist" : "Jimi Hendrix",
|
"album_artist" : "Jimi Hendrix",
|
||||||
"artist" : "Jimi Hendrix",
|
"artist" : "Jimi Hendrix",
|
||||||
@@ -617,6 +618,7 @@ mod tests {
|
|||||||
"year" : 2016
|
"year" : 2016
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_song_queue() {
|
async fn test_song_queue() {
|
||||||
|
|||||||
Reference in New Issue
Block a user