From 162a333ecdfb6e9a76141eadc863aed056f2953b Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 18 Jul 2025 19:06:00 -0400 Subject: [PATCH] Added function to link user_id with songQueue record #156 --- src/callers/song.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/callers/song.rs b/src/callers/song.rs index a4c4856..a0bfea7 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -491,6 +491,33 @@ mod song_queue { } } + pub async fn link_user_id( + pool: &sqlx::PgPool, + id: &uuid::Uuid, + user_id: &uuid::Uuid, + ) -> Result { + let result = sqlx::query( + r#" + UPDATE "songQueue" SET user_id = $1 WHERE id = $2 RETURNING user_id; + "#, + ) + .bind(user_id) + .bind(id) + .fetch_one(pool) + .await + .map_err(|e| { + eprintln!("Error updating record {e}"); + }); + + match result { + Ok(row) => Ok(row + .try_get("user_id") + .map_err(|_e| sqlx::Error::RowNotFound) + .unwrap()), + Err(_) => Err(sqlx::Error::RowNotFound), + } + } + pub async fn get_song_queue( pool: &sqlx::PgPool, id: &uuid::Uuid,