tsk-271: Adding other endpoint
pr CI / Test Suite (pull_request) Failing after 1m22s

This commit is contained in:
phoenix committed 2026-11-21 12:20:17 -05:00
1 parent f48c7ee99c
commit e416aa6723
3 files changed
+159 -16

No files matched your search

+1
View File
@@ -17,6 +17,7 @@ pub mod endpoints {
pub const DOWNLOADCOVERART: &str = "/api/v2/coverart/download/{id}";
pub const CREATEPLAYBACKQUEUE: &str = "/api/v2/playback/queue";
pub const GETPLAYBACKQUEUE: &str = "/api/v2/playback/queue";
}
pub mod response {
+121 -10
View File
@@ -1,4 +1,9 @@
pub mod queue {
use axum::http;
use tower_http::classify::StatusInRangeFailureClass::StatusCode;
use crate::callers::playback::queue::response::GetPlaybackQueueResponse;
const PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER: &str = "BROWSER";
const PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE: &str = "MOBILE";
@@ -14,6 +19,9 @@ pub mod queue {
}
pub mod request {
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
pub mod create_playback_queue {
use serde::{Deserialize, Serialize};
@@ -41,9 +49,19 @@ pub mod queue {
}
}
}
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
pub struct GetPlaybackQueueParams {
pub id: Option<uuid::Uuid>,
pub device_type: Option<String>,
pub user_id: Option<uuid::Uuid>,
}
}
pub mod response {
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
pub mod create_playback_queue {
use serde::{Deserialize, Serialize};
@@ -53,41 +71,54 @@ pub mod queue {
pub data: Vec<super::super::PlaybackQueue>,
}
}
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
pub struct GetPlaybackQueueResponse {
pub message: String,
pub data: Vec<super::PlaybackQueue>,
}
}
pub mod endpoint {
use axum::{Extension, Json, http};
use axum::extract::Query;
use http::StatusCode;
use super::super::super::response as response_message;
use super::super::super::endpoints;
use super::request::create_playback_queue::CreatePlaybackQueueRequest;
use super::response::create_playback_queue::CreatePlaybackQueueResponse;
use super::request::GetPlaybackQueueParams;
use super::response::GetPlaybackQueueResponse;
use crate::repo::playback::queue as playback_repo;
#[utoipa::path(
post,
path = super::super::super::endpoints::CREATEPLAYBACKQUEUE,
path = endpoints::CREATEPLAYBACKQUEUE,
request_body(
content = super::request::create_playback_queue::CreatePlaybackQueueRequest,
content = CreatePlaybackQueueRequest,
description = "Create playback queue for a user",
content_type = "application/json"
),
responses(
(status = 200, description = "Queue already exists", body = super::response::create_playback_queue::CreatePlaybackQueueResponse),
(status = 201, description = "Playback queue created", body = super::response::create_playback_queue::CreatePlaybackQueueResponse),
(status = 400, description = "Bad request", body = super::response::create_playback_queue::CreatePlaybackQueueResponse),
(status = 505, description = "Something went wrong", body = super::response::create_playback_queue::CreatePlaybackQueueResponse)
(status = 200, description = "Queue already exists", body = CreatePlaybackQueueResponse),
(status = 201, description = "Playback queue created", body = CreatePlaybackQueueResponse),
(status = 400, description = "Bad request", body = CreatePlaybackQueueResponse),
(status = 505, description = "Something went wrong", body = CreatePlaybackQueueResponse)
)
)]
pub async fn create_playback_queue(
Extension(pool): Extension<sqlx::PgPool>,
Json(payload): Json<super::request::create_playback_queue::CreatePlaybackQueueRequest>,
Json(payload): Json<CreatePlaybackQueueRequest>,
) -> (
axum::http::StatusCode,
axum::Json<super::response::create_playback_queue::CreatePlaybackQueueResponse>,
StatusCode,
Json<CreatePlaybackQueueResponse>,
) {
let mut response =
super::response::create_playback_queue::CreatePlaybackQueueResponse::default();
if !payload.is_valid() {
response.message = super::super::super::response::INVALID.to_string();
response.message = response_message::INVALID.to_string();
(StatusCode::BAD_REQUEST, Json(response))
} else {
let res = match playback_repo::queue_existence_search(
@@ -134,5 +165,85 @@ pub mod queue {
}
}
}
#[utoipa::path(
get,
path = endpoints::GETPLAYBACKQUEUE,
params(
("id" = uuid::Uuid, Path, description = "Id of playback queue"),
("device_type" = String, Path, description = "Device type of queue"),
("user_id" = uuid::Uuid, Path, description = "User Id")
),
responses(
(status = 200, description = "Playback queue found", body = GetPlaybackQueueResponse),
(status = 400, description = "Error getting songs", body = GetPlaybackQueueResponse)
)
)]
pub async fn get_playback_queue(Extension(pool): Extension<sqlx::PgPool>,
Query(params): Query<GetPlaybackQueueParams>,) -> (StatusCode, Json<GetPlaybackQueueResponse>) {
let mut response = GetPlaybackQueueResponse::default();
match params.id {
Some(id) => {
match playback_repo::get(&pool, &id).await {
Ok(playback_queue) => {
response.message = response_message::SUCCESSFUL.to_string();
response.data.push(playback_queue);
(StatusCode::OK, Json(response))
},
Err(err) => {
eprintln!("Error: {err:?}");
response.message = err.to_string();
(StatusCode::INTERNAL_SERVER_ERROR, Json(response))
}
}
},
None => match params.user_id {
Some(user_id) => {
let device_type = match params.device_type {
Some(d) => {
d
},
None => {
response.message = response_message::INVALID.to_string();
return (StatusCode::BAD_REQUEST, Json(response));
}
};
let exists = match playback_repo::queue_existence_search(&pool, &device_type, &user_id).await {
Ok(res) => {
res
},
Err(err) => {
eprintln!("Error: {err:?}");
response.message = err.to_string();
return (StatusCode::INTERNAL_SERVER_ERROR, Json(response));
}
};
if exists {
match playback_repo::get_with_device_type_and_user_id(&pool, &device_type, &user_id).await {
Ok(playback_queue) => {
response.message = response_message::SUCCESSFUL.to_string();
response.data.push(playback_queue);
(StatusCode::OK, Json(response))
},
Err(err) => {
eprintln!("Error: {err:?}");
response.message = err.to_string();
(StatusCode::INTERNAL_SERVER_ERROR, Json(response))
}
}
} else {
(StatusCode::OK, Json(response))
}
},
None => {
response.message = response_message::INVALID.to_string();
(StatusCode::BAD_REQUEST, Json(response))
}
}
}
}
}
}
+37 -6
View File
@@ -1,9 +1,10 @@
pub mod queue {
use sqlx::{PgPool, Row};
// use sqlx::postgres::PgRow;
use crate::callers::playback::queue::PlaybackQueue;
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,
@@ -61,10 +62,41 @@ pub mod queue {
}
}
// TODO: For later
/*
pub async fn get(pool: &PgPool, id: &uuid::Uuid) -> Result<PlaybackQueue, SqlxError> {
let query = r#"
SELECT id, name, device_type, user_id, date_created
FROM "playbackQueue"
WHERE id = $1
"#;
match sqlx::query(query)
.bind(id)
.fetch_one(pool)
.await {
Ok(row) => parse_row(&row).await,
Err(err) => Err(err)
}
}
pub async fn get_with_device_type_and_user_id(pool: &PgPool, device_type: &str, user_id: &uuid::Uuid) -> Result<PlaybackQueue, SqlxError> {
let query = r#"
SELECT id, name, device_type, user_id, date_created
FROM "playbackQueue"
WHERE device_type = $1 AND user_id = $2
"#;
match sqlx::query(query)
.bind(device_type)
.bind(user_id)
.fetch_one(pool)
.await {
Ok(row) => parse_row(&row).await,
Err(err) => Err(err)
}
}
async fn parse_row(row: &PgRow) -> Result<PlaybackQueue, SqlxError> {
Ok(PlayBackQueue {
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(),
@@ -72,5 +104,4 @@ pub mod queue {
date_created: row.try_get("date_created").map_err(|_e| SqlxError::RowNotFound).unwrap()
})
}
*/
}