From 435e39b530e62ca25488235ce81214ead596ca77 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Mon, 19 May 2025 21:01:36 -0400 Subject: [PATCH] Added more functionality --- src/callers/coverart.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/callers/coverart.rs b/src/callers/coverart.rs index 478b749..33cfd2b 100644 --- a/src/callers/coverart.rs +++ b/src/callers/coverart.rs @@ -17,10 +17,16 @@ pub mod response { } pub mod link { + #[derive(Debug, serde::Deserialize, serde::Serialize)] + pub struct Id { + pub coverart_id: uuid::Uuid, + pub song_queue_id: uuid::Uuid, + } + #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] pub struct Response { pub message: String, - pub data: Vec, + pub data: Vec, } } } @@ -54,7 +60,24 @@ mod db { } pub async fn update(pool: &sqlx::PgPool, coverart_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,) -> Result { - Ok(0) + let result = sqlx::query( + r#" + UPDATE "coverartQueue" SET song_queue_id = $1 WHERE id = $2; + "# + ) + .bind(song_queue_id) + .bind(coverart_id) + .execute(pool) + .await; + + match result { + Ok(_) => { + Ok(0) + } + Err(_err) => { + Err(sqlx::Error::RowNotFound) + } + } } } @@ -113,7 +136,12 @@ pub mod endpoint { let song_queue_id = payload.song_queue_id; match super::db::update(&pool, &coverart_id, &song_queue_id).await { - Ok(o) => { + Ok(_o) => { + response.data.push(super::response::link::Id { + song_queue_id: song_queue_id, + coverart_id: coverart_id, + }); + (axum::http::StatusCode::OK, axum::Json(response)) } Err(err) => {