Added initial code for endpoint to link user id with song queue #156

This commit is contained in:
kdeng00
2025-07-18 19:01:53 -04:00
parent c9bcea5f98
commit c5f0d5fae8
+30
View File
@@ -84,6 +84,14 @@ pub mod request {
pub song_queue_id: uuid::Uuid, pub song_queue_id: uuid::Uuid,
} }
} }
pub mod link_user_id {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Request {
pub song_queue_id: uuid::Uuid,
pub user_id: uuid::Uuid,
}
}
} }
pub mod response { pub mod response {
@@ -142,6 +150,14 @@ pub mod response {
pub data: Vec<uuid::Uuid>, pub data: Vec<uuid::Uuid>,
} }
} }
pub mod link_user_id {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}
} }
// TODO: Might make a distinction between year and date in a song's tag at some point // TODO: Might make a distinction between year and date in a song's tag at some point
@@ -616,6 +632,20 @@ pub mod endpoint {
(StatusCode::OK, Json(response)) (StatusCode::OK, Json(response))
} }
pub async fn link_user_id(axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Json(payload): axum::Json<super::request::link_user_id::Request>) -> (axum::http::StatusCode, axum::Json<super::response::link_user_id::Response>) {
let mut response = super::response::link_user_id::Response::default();
match super::song_queue::get_song_queue(&pool, &payload.song_queue_id).await {
Ok(song_queue) => {
(axum::http::StatusCode::OK, axum::Json(response))
}
Err(err) => {
response.message = err.to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
}
}
pub async fn fetch_queue_song( pub async fn fetch_queue_song(
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
) -> ( ) -> (