Added initial code to link coverart id and song queue id

This commit is contained in:
kdeng00
2025-05-19 20:46:36 -04:00
parent ddb0bf27f8
commit d242ec37a5
3 changed files with 48 additions and 1 deletions
+42
View File
@@ -1,9 +1,28 @@
pub mod request {
pub mod link {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct Request {
pub coverart_id: uuid::Uuid,
pub song_queue_id: uuid::Uuid,
}
}
}
pub mod response {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
pub mod link {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}
}
mod db {
@@ -33,6 +52,10 @@ mod db {
Err(_err) => Err(sqlx::Error::RowNotFound),
}
}
pub async fn update(pool: &sqlx::PgPool, coverart_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,) -> Result<i32, sqlx::Error> {
Ok(0)
}
}
pub mod endpoint {
@@ -80,4 +103,23 @@ pub mod endpoint {
}
}
}
pub async fn link(
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::Json(payload): axum::Json<super::request::link::Request>,
) -> (axum::http::StatusCode, axum::Json<super::response::link::Response>,) {
let mut response = super::response::link::Response::default();
let coverart_id = payload.coverart_id;
let song_queue_id = payload.song_queue_id;
match super::db::update(&pool, &coverart_id, &song_queue_id).await {
Ok(o) => {
(axum::http::StatusCode::OK, axum::Json(response))
}
Err(err) => {
response.message = err.to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
}
}
}
}
+1
View File
@@ -8,4 +8,5 @@ pub mod endpoints {
pub const NEXTQUEUESONG: &str = "/api/v2/song/queue/next";
pub const QUEUEMETADATA: &str = "/api/v2/song/metadata/queue";
pub const QUEUECOVERART: &str = "/api/v2/coverart/queue";
pub const QUEUECOVERARTLINK: &str = "/api/v2/coverart/queue/link";
}
+5 -1
View File
@@ -58,7 +58,7 @@ async fn main() {
}
pub mod init {
use axum::routing::{get, post};
use axum::routing::{get, patch, post};
use std::time::Duration;
use tower_http::timeout::TimeoutLayer;
@@ -89,6 +89,10 @@ pub mod init {
crate::callers::endpoints::QUEUECOVERART,
post(crate::callers::coverart::endpoint::queue),
)
.route(
crate::callers::endpoints::QUEUECOVERARTLINK,
patch(crate::callers::coverart::endpoint::link),
)
}
pub async fn app() -> axum::Router {