tsk-271: Adding more code
pr CI / Test Suite (pull_request) Failing after 1m16s

This commit is contained in:
phoenix committed 2026-11-20 15:08:43 -05:00
1 parent 4403f3c7d2
commit 4ee0ba59fd
4 files changed
+143

No files matched your search

+4
View File
@@ -1,4 +1,5 @@
pub mod coverart; pub mod coverart;
pub mod playback;
pub mod queue; pub mod queue;
pub mod song; pub mod song;
@@ -14,10 +15,13 @@ pub mod endpoints {
pub const CREATECOVERART: &str = "/api/v2/coverart"; pub const CREATECOVERART: &str = "/api/v2/coverart";
pub const GETCOVERART: &str = "/api/v2/coverart"; pub const GETCOVERART: &str = "/api/v2/coverart";
pub const DOWNLOADCOVERART: &str = "/api/v2/coverart/download/{id}"; pub const DOWNLOADCOVERART: &str = "/api/v2/coverart/download/{id}";
pub const CREATEPLAYBACKQUEUE: &str = "/api/v2/playback/queue";
} }
pub mod response { pub mod response {
pub const SUCCESSFUL: &str = "SUCCESSFUL"; pub const SUCCESSFUL: &str = "SUCCESSFUL";
pub const INVALID: &str = "INVALID";
} }
/// Basic handler that responds with a static string /// Basic handler that responds with a static string
+88
View File
@@ -0,0 +1,88 @@
pub mod queue {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct PlaybackQueue {
pub id: uuid::Uuid,
pub name: String,
pub device_type: String,
pub user_id: uuid::Uuid,
#[serde(with = "time::serde::rfc3339::option")]
pub date_created: Option<time::OffsetDateTime>
}
pub mod request {
pub mod create_playback_queue {
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct CreatePlaybackQueueRequest {
pub name: String,
pub device_type: String,
pub user_id: uuid::Uuid
}
impl CreatePlaybackQueueRequest {
pub fn is_valid(&self) -> bool {
!self.user_id.is_nil() && !self.name.is_empty() && !self.user_id.is_nil()
}
}
}
}
pub mod response {
pub mod create_playback_queue {
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct CreatePlaybackQueueResponse {
pub message: String,
pub data: Vec<super::super::PlaybackQueue>,
}
}
}
pub mod endpoint {
use axum::{http, Extension, Json};
use http::StatusCode;
use crate::repo::playback as playback_repo;
pub async fn create_playback_queue(
Extension(pool): Extension<sqlx::PgPool>,
Json(payload): Json<super::request::create_playback_queue::CreatePlaybackQueueRequest>,
) -> (
axum::http::StatusCode,
axum::Json<super::response::create_playback_queue::CreatePlaybackQueueResponse>,
) {
let mut response = super::response::create_playback_queue::CreatePlaybackQueueResponse::default();
if !payload.is_valid() {
response.message = super::super::super::response::INVALID.to_string();
(StatusCode::BAD_REQUEST, Json(response))
} else {
let res = match playback_repo::queue::queue_existence_search(&pool, &payload.device_type, &payload.user_id).await {
Ok(result) => {
result
}
Err(err) => {
eprintln!("Error: {err:?}");
response.message = err.to_string();
return (StatusCode::INTERNAL_SERVER_ERROR, Json(response))
}
};
if res {
// Do not create plaback queue
} else {
}
(StatusCode::OK, Json(response))
}
}
}
}
+1
View File
@@ -1,3 +1,4 @@
pub mod coverart; pub mod coverart;
pub mod playback;
pub mod queue; pub mod queue;
pub mod song; pub mod song;
+50
View File
@@ -0,0 +1,50 @@
pub mod queue {
use sqlx::{PgPool, Row};
// use sqlx::postgres::PgRow;
use sqlx::Error as SqlxError;
use crate::callers::playback::queue::PlaybackQueue;
pub async fn create_queue(pool: &PgPool, playback_queue: &PlaybackQueue) -> Result<(time::OffsetDateTime, uuid::Uuid), SqlxError> {
let query = r#"
INSERT INTO "playbackQueue" (name, device_type, user_id)
VALUES ($1, $2, $3)
RETURNING date_created, id;
"#;
match sqlx::query(query)
.bind(&playback_queue.name)
.bind(&playback_queue.device_type)
.bind(&playback_queue.user_id)
.fetch_one(pool)
.await {
Ok(row) => {
let id = row.try_get("id").map_err(|_e| SqlxError::RowNotFound).unwrap();
let date_created = row.try_get("date_created").map_err(|_e| SqlxError::RowNotFound).unwrap();
Ok((id, date_created))
}
Err(err) => {
Err(err)
}
}
}
pub async fn queue_existence_search(pool: &PgPool, device_type: &str, user_id: &uuid::Uuid) -> Result<bool, SqlxError> {
Ok(false)
}
// TODO: For later
/*
async fn parse_row(row: &PgRow) -> Result<PlaybackQueue, SqlxError> {
Ok(PlayBackQueue {
id: row.try_get("id").map_err(|_e| SqlxError::RowNotFound).unwrap(),
name: row.try_get("name").map_err(|_e| SqlxError::RowNotFound).unwrap(),
device_type: row.try_get("device_type").map_err(|_e| SqlxError::RowNotFound).unwrap(),
user_id: row.try_get("user_id").map_err(|_e| SqlxError::RowNotFound).unwrap(),
date_created: row.try_get("date_created").map_err(|_e| SqlxError::RowNotFound).unwrap()
})
}
*/
}