tsk-271: More code

This commit is contained in:
phoenix committed 2026-11-20 15:21:32 -05:00
1 parent 4ee0ba59fd
commit ed82e59a26
1 file changed
+37 -4
+37 -4
View File
@@ -3,6 +3,9 @@
pub mod queue { pub mod queue {
const PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER: &str = "BROWSER";
const PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE: &str = "MOBILE";
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)] #[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct PlaybackQueue { pub struct PlaybackQueue {
pub id: uuid::Uuid, pub id: uuid::Uuid,
@@ -26,7 +29,17 @@ pub struct PlaybackQueue {
impl CreatePlaybackQueueRequest { impl CreatePlaybackQueueRequest {
pub fn is_valid(&self) -> bool { pub fn is_valid(&self) -> bool {
!self.user_id.is_nil() && !self.name.is_empty() && !self.user_id.is_nil() let pre_check = !self.user_id.is_nil() && !self.name.is_empty() && !self.user_id.is_nil();
pre_check && self.valid_device_type()
}
fn valid_device_type(&self) -> bool {
match self.device_type.as_str() {
super::super::PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER => true,
super::super::PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE => true,
_ => false,
}
} }
} }
} }
@@ -47,6 +60,7 @@ pub struct PlaybackQueue {
pub mod endpoint { pub mod endpoint {
use axum::{http, Extension, Json}; use axum::{http, Extension, Json};
use http::StatusCode; use http::StatusCode;
// use josekit::jwe::zip::deflate::DeflateJweCompression::Def;
use crate::repo::playback as playback_repo; use crate::repo::playback as playback_repo;
@@ -77,12 +91,31 @@ pub struct PlaybackQueue {
if res { if res {
// Do not create plaback queue // Do not create plaback queue
response.message = "Already created".to_string();
(StatusCode::OK, Json(response))
} else { } else {
} let mut playback_queue = super::PlaybackQueue {
name: payload.name,
device_type: payload.device_type,
user_id: payload.user_id,
..Default::default()
};
match playback_repo::queue::create_queue(&pool, &playback_queue).await {
Ok((id, date_created)) => {
playback_queue.id = id;
playback_queue.date_created = Some(date_created);
response.data.push(playback_queue);
response.message = super::super::super::response::SUCCESSFUL.to_string();
(StatusCode::OK, Json(response)) (StatusCode::CREATED, Json(response))
}
Err(err) => {
eprintln!("Error: {err:?}");
(StatusCode::INTERNAL_SERVER_ERROR, Json(response))
}
}
}
} }
} }
} }
} }