This commit is contained in:
4 files changed
+149
-154
No files matched your search
+46
-43
@@ -1,6 +1,5 @@
|
|||||||
pub mod queue {
|
pub mod queue {
|
||||||
|
|
||||||
|
|
||||||
const PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER: &str = "BROWSER";
|
const PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER: &str = "BROWSER";
|
||||||
const PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE: &str = "MOBILE";
|
const PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE: &str = "MOBILE";
|
||||||
|
|
||||||
@@ -19,8 +18,10 @@ pub mod queue {
|
|||||||
use utoipa::ToSchema;
|
use utoipa::ToSchema;
|
||||||
|
|
||||||
pub mod create_playback_queue {
|
pub mod create_playback_queue {
|
||||||
|
use super::super::{
|
||||||
|
PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER, PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE,
|
||||||
|
};
|
||||||
use super::{Deserialize, Serialize, ToSchema};
|
use super::{Deserialize, Serialize, ToSchema};
|
||||||
use super::super::{PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE, PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
|
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
|
||||||
pub struct CreatePlaybackQueueRequest {
|
pub struct CreatePlaybackQueueRequest {
|
||||||
@@ -40,8 +41,7 @@ pub mod queue {
|
|||||||
fn valid_device_type(&self) -> bool {
|
fn valid_device_type(&self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
self.device_type.as_str(),
|
self.device_type.as_str(),
|
||||||
PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER
|
PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER | PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE
|
||||||
| PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,13 +56,13 @@ pub mod queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod response {
|
pub mod response {
|
||||||
|
use super::PlaybackQueue;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use utoipa::ToSchema;
|
use utoipa::ToSchema;
|
||||||
use super::PlaybackQueue;
|
|
||||||
|
|
||||||
pub mod create_playback_queue {
|
pub mod create_playback_queue {
|
||||||
use super::{Deserialize, Serialize, ToSchema};
|
|
||||||
use super::PlaybackQueue;
|
use super::PlaybackQueue;
|
||||||
|
use super::{Deserialize, Serialize, ToSchema};
|
||||||
|
|
||||||
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
|
#[derive(Debug, Default, Deserialize, Serialize, ToSchema)]
|
||||||
pub struct CreatePlaybackQueueResponse {
|
pub struct CreatePlaybackQueueResponse {
|
||||||
@@ -79,17 +79,17 @@ pub mod queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod endpoint {
|
pub mod endpoint {
|
||||||
use axum::{Extension, Json, http};
|
|
||||||
use axum::extract::Query;
|
use axum::extract::Query;
|
||||||
|
use axum::{Extension, Json, http};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
|
|
||||||
use super::super::super::response as response_message;
|
|
||||||
use super::super::super::endpoints;
|
use super::super::super::endpoints;
|
||||||
|
use super::super::super::response as response_message;
|
||||||
use super::PlaybackQueue;
|
use super::PlaybackQueue;
|
||||||
use super::request::create_playback_queue::CreatePlaybackQueueRequest;
|
|
||||||
use super::response::create_playback_queue::CreatePlaybackQueueResponse;
|
|
||||||
use super::request::GetPlaybackQueueParams;
|
use super::request::GetPlaybackQueueParams;
|
||||||
|
use super::request::create_playback_queue::CreatePlaybackQueueRequest;
|
||||||
use super::response::GetPlaybackQueueResponse;
|
use super::response::GetPlaybackQueueResponse;
|
||||||
|
use super::response::create_playback_queue::CreatePlaybackQueueResponse;
|
||||||
use crate::repo::playback::queue as playback_repo;
|
use crate::repo::playback::queue as playback_repo;
|
||||||
|
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
@@ -110,12 +110,8 @@ pub mod queue {
|
|||||||
pub async fn create_playback_queue(
|
pub async fn create_playback_queue(
|
||||||
Extension(pool): Extension<sqlx::PgPool>,
|
Extension(pool): Extension<sqlx::PgPool>,
|
||||||
Json(payload): Json<CreatePlaybackQueueRequest>,
|
Json(payload): Json<CreatePlaybackQueueRequest>,
|
||||||
) -> (
|
) -> (StatusCode, Json<CreatePlaybackQueueResponse>) {
|
||||||
StatusCode,
|
let mut response = CreatePlaybackQueueResponse::default();
|
||||||
Json<CreatePlaybackQueueResponse>,
|
|
||||||
) {
|
|
||||||
let mut response =
|
|
||||||
CreatePlaybackQueueResponse::default();
|
|
||||||
|
|
||||||
if !payload.is_valid() {
|
if !payload.is_valid() {
|
||||||
response.message = response_message::INVALID.to_string();
|
response.message = response_message::INVALID.to_string();
|
||||||
@@ -152,8 +148,7 @@ pub mod queue {
|
|||||||
playback_queue.id = id;
|
playback_queue.id = id;
|
||||||
playback_queue.date_created = Some(date_created);
|
playback_queue.date_created = Some(date_created);
|
||||||
response.data.push(playback_queue);
|
response.data.push(playback_queue);
|
||||||
response.message =
|
response.message = response_message::SUCCESSFUL.to_string();
|
||||||
response_message::SUCCESSFUL.to_string();
|
|
||||||
|
|
||||||
(StatusCode::CREATED, Json(response))
|
(StatusCode::CREATED, Json(response))
|
||||||
}
|
}
|
||||||
@@ -179,41 +174,43 @@ pub mod queue {
|
|||||||
(status = 400, description = "Error getting songs", body = GetPlaybackQueueResponse)
|
(status = 400, description = "Error getting songs", body = GetPlaybackQueueResponse)
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
pub async fn get_playback_queue(Extension(pool): Extension<sqlx::PgPool>,
|
pub async fn get_playback_queue(
|
||||||
Query(params): Query<GetPlaybackQueueParams>,) -> (StatusCode, Json<GetPlaybackQueueResponse>) {
|
Extension(pool): Extension<sqlx::PgPool>,
|
||||||
|
Query(params): Query<GetPlaybackQueueParams>,
|
||||||
|
) -> (StatusCode, Json<GetPlaybackQueueResponse>) {
|
||||||
let mut response = GetPlaybackQueueResponse::default();
|
let mut response = GetPlaybackQueueResponse::default();
|
||||||
|
|
||||||
match params.id {
|
match params.id {
|
||||||
Some(id) => {
|
Some(id) => match playback_repo::get(&pool, &id).await {
|
||||||
match playback_repo::get(&pool, &id).await {
|
Ok(playback_queue) => {
|
||||||
Ok(playback_queue) => {
|
response.message = response_message::SUCCESSFUL.to_string();
|
||||||
response.message = response_message::SUCCESSFUL.to_string();
|
response.data.push(playback_queue);
|
||||||
response.data.push(playback_queue);
|
(StatusCode::OK, Json(response))
|
||||||
(StatusCode::OK, Json(response))
|
}
|
||||||
},
|
Err(err) => {
|
||||||
Err(err) => {
|
eprintln!("Error: {err:?}");
|
||||||
eprintln!("Error: {err:?}");
|
response.message = err.to_string();
|
||||||
response.message = err.to_string();
|
(StatusCode::INTERNAL_SERVER_ERROR, Json(response))
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(response))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => match params.user_id {
|
None => match params.user_id {
|
||||||
Some(user_id) => {
|
Some(user_id) => {
|
||||||
let device_type = match params.device_type {
|
let device_type = match params.device_type {
|
||||||
Some(d) => {
|
Some(d) => d,
|
||||||
d
|
|
||||||
},
|
|
||||||
None => {
|
None => {
|
||||||
response.message = response_message::INVALID.to_string();
|
response.message = response_message::INVALID.to_string();
|
||||||
return (StatusCode::BAD_REQUEST, Json(response));
|
return (StatusCode::BAD_REQUEST, Json(response));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let exists = match playback_repo::queue_existence_search(&pool, &device_type, &user_id).await {
|
let exists = match playback_repo::queue_existence_search(
|
||||||
Ok(res) => {
|
&pool,
|
||||||
res
|
&device_type,
|
||||||
},
|
&user_id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(res) => res,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
response.message = err.to_string();
|
response.message = err.to_string();
|
||||||
@@ -222,12 +219,18 @@ pub mod queue {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if exists {
|
if exists {
|
||||||
match playback_repo::get_with_device_type_and_user_id(&pool, &device_type, &user_id).await {
|
match playback_repo::get_with_device_type_and_user_id(
|
||||||
|
&pool,
|
||||||
|
&device_type,
|
||||||
|
&user_id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(playback_queue) => {
|
Ok(playback_queue) => {
|
||||||
response.message = response_message::SUCCESSFUL.to_string();
|
response.message = response_message::SUCCESSFUL.to_string();
|
||||||
response.data.push(playback_queue);
|
response.data.push(playback_queue);
|
||||||
(StatusCode::OK, Json(response))
|
(StatusCode::OK, Json(response))
|
||||||
},
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
response.message = err.to_string();
|
response.message = err.to_string();
|
||||||
@@ -237,12 +240,12 @@ pub mod queue {
|
|||||||
} else {
|
} else {
|
||||||
(StatusCode::OK, Json(response))
|
(StatusCode::OK, Json(response))
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
None => {
|
None => {
|
||||||
response.message = response_message::INVALID.to_string();
|
response.message = response_message::INVALID.to_string();
|
||||||
(StatusCode::BAD_REQUEST, Json(response))
|
(StatusCode::BAD_REQUEST, Json(response))
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-80
@@ -1,7 +1,7 @@
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use axum::routing::{delete, get, patch, post};
|
|
||||||
use axum::body::Body as AxumBody;
|
use axum::body::Body as AxumBody;
|
||||||
|
use axum::routing::{delete, get, patch, post};
|
||||||
use tower_http::timeout::TimeoutLayer;
|
use tower_http::timeout::TimeoutLayer;
|
||||||
use utoipa::OpenApi;
|
use utoipa::OpenApi;
|
||||||
|
|
||||||
@@ -9,12 +9,12 @@ use crate::auth::auth;
|
|||||||
use crate::callers;
|
use crate::callers;
|
||||||
use crate::db;
|
use crate::db;
|
||||||
use callers::coverart as coverart_caller;
|
use callers::coverart as coverart_caller;
|
||||||
|
use callers::endpoints;
|
||||||
use callers::playback::queue as playback_caller;
|
use callers::playback::queue as playback_caller;
|
||||||
use callers::queue::coverart as coverart_queue_callers;
|
use callers::queue::coverart as coverart_queue_callers;
|
||||||
use callers::queue::metadata as metadata_queue_caller;
|
use callers::queue::metadata as metadata_queue_caller;
|
||||||
use callers::queue::song as song_queue_callers;
|
use callers::queue::song as song_queue_callers;
|
||||||
use callers::song as song_caller;
|
use callers::song as song_caller;
|
||||||
use callers::endpoints;
|
|
||||||
|
|
||||||
use coverart_caller::endpoint as coverart_endpoints;
|
use coverart_caller::endpoint as coverart_endpoints;
|
||||||
use coverart_caller::response as coverart_responses;
|
use coverart_caller::response as coverart_responses;
|
||||||
@@ -103,164 +103,134 @@ pub async fn routes() -> axum::Router {
|
|||||||
.route(endpoints::ROOT, get(callers::root))
|
.route(endpoints::ROOT, get(callers::root))
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUESONG,
|
callers::queue::endpoints::QUEUESONG,
|
||||||
post(callers::queue::song::endpoint::queue_song).route_layer(
|
post(callers::queue::song::endpoint::queue_song)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUESONG,
|
callers::queue::endpoints::QUEUESONG,
|
||||||
patch(callers::queue::song::endpoint::update_song_queue_status).route_layer(
|
patch(callers::queue::song::endpoint::update_song_queue_status)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUESONGLINKUSERID,
|
callers::queue::endpoints::QUEUESONGLINKUSERID,
|
||||||
patch(callers::queue::song::endpoint::link_user_id).route_layer(
|
patch(callers::queue::song::endpoint::link_user_id)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUESONGDATA,
|
callers::queue::endpoints::QUEUESONGDATA,
|
||||||
get(callers::queue::song::endpoint::download_queued_song).route_layer(
|
get(callers::queue::song::endpoint::download_queued_song)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::NEXTQUEUESONG,
|
callers::queue::endpoints::NEXTQUEUESONG,
|
||||||
get(callers::queue::song::endpoint::fetch_queue_song).route_layer(
|
get(callers::queue::song::endpoint::fetch_queue_song)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUESONGUPDATE,
|
callers::queue::endpoints::QUEUESONGUPDATE,
|
||||||
patch(callers::queue::song::endpoint::update_song_queue).route_layer(
|
patch(callers::queue::song::endpoint::update_song_queue)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUESONGDATAWIPE,
|
callers::queue::endpoints::QUEUESONGDATAWIPE,
|
||||||
patch(callers::queue::song::endpoint::wipe_data_from_song_queue).route_layer(
|
patch(callers::queue::song::endpoint::wipe_data_from_song_queue)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUEMETADATA,
|
callers::queue::endpoints::QUEUEMETADATA,
|
||||||
post(callers::queue::metadata::endpoint::queue_metadata).route_layer(
|
post(callers::queue::metadata::endpoint::queue_metadata)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUEMETADATA,
|
callers::queue::endpoints::QUEUEMETADATA,
|
||||||
get(callers::queue::metadata::endpoint::fetch_metadata).route_layer(
|
get(callers::queue::metadata::endpoint::fetch_metadata)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUECOVERART,
|
callers::queue::endpoints::QUEUECOVERART,
|
||||||
post(callers::queue::coverart::endpoint::queue).route_layer(
|
post(callers::queue::coverart::endpoint::queue)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUECOVERARTDATA,
|
callers::queue::endpoints::QUEUECOVERARTDATA,
|
||||||
get(callers::queue::coverart::endpoint::fetch_coverart_with_data).route_layer(
|
get(callers::queue::coverart::endpoint::fetch_coverart_with_data)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUECOVERART,
|
callers::queue::endpoints::QUEUECOVERART,
|
||||||
get(callers::queue::coverart::endpoint::fetch_coverart_no_data).route_layer(
|
get(callers::queue::coverart::endpoint::fetch_coverart_no_data)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUECOVERARTLINK,
|
callers::queue::endpoints::QUEUECOVERARTLINK,
|
||||||
patch(callers::queue::coverart::endpoint::link).route_layer(
|
patch(callers::queue::coverart::endpoint::link)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
callers::queue::endpoints::QUEUECOVERARTDATAWIPE,
|
callers::queue::endpoints::QUEUECOVERARTDATAWIPE,
|
||||||
patch(callers::queue::coverart::endpoint::wipe_data_from_coverart_queue)
|
patch(callers::queue::coverart::endpoint::wipe_data_from_coverart_queue)
|
||||||
.route_layer(axum::middleware::from_fn(
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
auth::<AxumBody>,
|
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::CREATESONG,
|
endpoints::CREATESONG,
|
||||||
post(callers::song::endpoint::create_metadata).route_layer(
|
post(callers::song::endpoint::create_metadata)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::CREATECOVERART,
|
endpoints::CREATECOVERART,
|
||||||
post(callers::coverart::endpoint::create_coverart).route_layer(
|
post(callers::coverart::endpoint::create_coverart)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::GETSONGS,
|
endpoints::GETSONGS,
|
||||||
get(callers::song::endpoint::get_songs).route_layer(axum::middleware::from_fn(
|
get(callers::song::endpoint::get_songs)
|
||||||
auth::<AxumBody>,
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
)),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::GETCOVERART,
|
endpoints::GETCOVERART,
|
||||||
get(callers::coverart::endpoint::get_coverart).route_layer(
|
get(callers::coverart::endpoint::get_coverart)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::DOWNLOADCOVERART,
|
endpoints::DOWNLOADCOVERART,
|
||||||
get(callers::coverart::endpoint::download_coverart).route_layer(
|
get(callers::coverart::endpoint::download_coverart)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::STREAMSONG,
|
endpoints::STREAMSONG,
|
||||||
get(callers::song::endpoint::stream_song).route_layer(
|
get(callers::song::endpoint::stream_song)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::DOWNLOADSONG,
|
endpoints::DOWNLOADSONG,
|
||||||
get(callers::song::endpoint::download_song).route_layer(
|
get(callers::song::endpoint::download_song)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::DELETESONG,
|
endpoints::DELETESONG,
|
||||||
delete(callers::song::endpoint::delete_song).route_layer(
|
delete(callers::song::endpoint::delete_song)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::GETALLSONGS,
|
endpoints::GETALLSONGS,
|
||||||
get(callers::song::endpoint::get_all_songs).route_layer(
|
get(callers::song::endpoint::get_all_songs)
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::CREATEPLAYBACKQUEUE,
|
endpoints::CREATEPLAYBACKQUEUE,
|
||||||
post(playback_endpoints::create_playback_queue)
|
post(playback_endpoints::create_playback_queue)
|
||||||
.route_layer(
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
endpoints::GETPLAYBACKQUEUE,
|
endpoints::GETPLAYBACKQUEUE,
|
||||||
get(playback_endpoints::get_playback_queue)
|
get(playback_endpoints::get_playback_queue)
|
||||||
.route_layer(
|
.route_layer(axum::middleware::from_fn(auth::<AxumBody>)),
|
||||||
axum::middleware::from_fn(auth::<AxumBody>),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.layer(cors::configure_cors().await)
|
.layer(cors::configure_cors().await)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn app() -> axum::Router {
|
pub async fn app() -> axum::Router {
|
||||||
let pool = db::create_pool()
|
let pool = db::create_pool().await.expect("Failed to create pool");
|
||||||
.await
|
|
||||||
.expect("Failed to create pool");
|
|
||||||
|
|
||||||
db::migrations(&pool).await;
|
db::migrations(&pool).await;
|
||||||
|
|
||||||
|
|||||||
+21
-16
@@ -184,16 +184,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod request {
|
mod request {
|
||||||
|
use axum::Router as AxumRouter;
|
||||||
|
use axum::http;
|
||||||
|
use axum::response::Response as AxumResponse;
|
||||||
use common_multipart_rfc7578::client::multipart::{
|
use common_multipart_rfc7578::client::multipart::{
|
||||||
Body as MultipartBody, Form as MultipartForm,
|
Body as MultipartBody, Form as MultipartForm,
|
||||||
};
|
};
|
||||||
use tower::ServiceExt;
|
|
||||||
use axum::http;
|
|
||||||
use axum::response::Response as AxumResponse;
|
|
||||||
use axum::Router as AxumRouter;
|
|
||||||
use http::Error as AxumHttpError;
|
use http::Error as AxumHttpError;
|
||||||
|
use tower::ServiceExt;
|
||||||
|
|
||||||
use super::{callers};
|
use super::callers;
|
||||||
|
|
||||||
pub async fn song_queue_req(
|
pub async fn song_queue_req(
|
||||||
app: &axum::Router,
|
app: &axum::Router,
|
||||||
@@ -298,14 +298,17 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_playback_queue(app: &AxumRouter, id: &uuid::Uuid) -> Result<AxumResponse, AxumHttpError> {
|
pub async fn get_playback_queue(
|
||||||
|
app: &AxumRouter,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<AxumResponse, AxumHttpError> {
|
||||||
let uri = format!("{}?id={}", callers::endpoints::GETPLAYBACKQUEUE, id);
|
let uri = format!("{}?id={}", callers::endpoints::GETPLAYBACKQUEUE, id);
|
||||||
match run_post(None, &uri, http::Method::GET, false).await {
|
match run_post(None, &uri, http::Method::GET, false).await {
|
||||||
Ok(request) => match app.clone().oneshot(request).await {
|
Ok(request) => match app.clone().oneshot(request).await {
|
||||||
Ok(response) => Ok(response),
|
Ok(response) => Ok(response),
|
||||||
Err(err) => Err(http::Error::from(err)),
|
Err(err) => Err(http::Error::from(err)),
|
||||||
},
|
},
|
||||||
Err(err) => Err(err)
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2102,8 +2105,8 @@ mod tests {
|
|||||||
use tower::ServiceExt;
|
use tower::ServiceExt;
|
||||||
|
|
||||||
use super::callers;
|
use super::callers;
|
||||||
use super::{db_mgr, init, request, util};
|
|
||||||
use super::test_data as outer_test_data;
|
use super::test_data as outer_test_data;
|
||||||
|
use super::{db_mgr, init, request, util};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_songs() {
|
async fn test_get_songs() {
|
||||||
@@ -2719,24 +2722,26 @@ mod tests {
|
|||||||
let device_type = outer_test_data::DEVICE_TYPE;
|
let device_type = outer_test_data::DEVICE_TYPE;
|
||||||
let name = outer_test_data::NAME;
|
let name = outer_test_data::NAME;
|
||||||
|
|
||||||
use callers::playback::queue::response::create_playback_queue::CreatePlaybackQueueResponse;
|
|
||||||
use callers::playback::queue::response::GetPlaybackQueueResponse;
|
use callers::playback::queue::response::GetPlaybackQueueResponse;
|
||||||
|
use callers::playback::queue::response::create_playback_queue::CreatePlaybackQueueResponse;
|
||||||
|
|
||||||
match request::create_playback_queue(&app, name, device_type, &user_id).await {
|
match request::create_playback_queue(&app, name, device_type, &user_id).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = util::get_resp_data::<
|
let resp = util::get_resp_data::<CreatePlaybackQueueResponse>(response).await;
|
||||||
CreatePlaybackQueueResponse
|
|
||||||
>(response)
|
|
||||||
.await;
|
|
||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
let playback_queue = &resp.data[0];
|
let playback_queue = &resp.data[0];
|
||||||
let playback_queue_id = playback_queue.id;
|
let playback_queue_id = playback_queue.id;
|
||||||
|
|
||||||
match request::get_playback_queue(&app, &playback_queue_id).await {
|
match request::get_playback_queue(&app, &playback_queue_id).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = util::get_resp_data::<GetPlaybackQueueResponse>(response).await;
|
let resp =
|
||||||
assert_eq!(false, resp.data.is_empty(), "Playback queue was created, but nothing returned");
|
util::get_resp_data::<GetPlaybackQueueResponse>(response).await;
|
||||||
},
|
assert_eq!(
|
||||||
|
false,
|
||||||
|
resp.data.is_empty(),
|
||||||
|
"Playback queue was created, but nothing returned"
|
||||||
|
);
|
||||||
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
assert!(false, "Error: {err:?}");
|
assert!(false, "Error: {err:?}");
|
||||||
|
|||||||
+32
-15
@@ -1,7 +1,7 @@
|
|||||||
pub mod queue {
|
pub mod queue {
|
||||||
use sqlx::{PgPool, Row};
|
|
||||||
use sqlx::postgres::PgRow;
|
|
||||||
use sqlx::Error as SqlxError;
|
use sqlx::Error as SqlxError;
|
||||||
|
use sqlx::postgres::PgRow;
|
||||||
|
use sqlx::{PgPool, Row};
|
||||||
|
|
||||||
use crate::callers::playback::queue::PlaybackQueue;
|
use crate::callers::playback::queue::PlaybackQueue;
|
||||||
|
|
||||||
@@ -69,16 +69,17 @@ pub mod queue {
|
|||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
match sqlx::query(query)
|
match sqlx::query(query).bind(id).fetch_one(pool).await {
|
||||||
.bind(id)
|
|
||||||
.fetch_one(pool)
|
|
||||||
.await {
|
|
||||||
Ok(row) => parse_row(&row).await,
|
Ok(row) => parse_row(&row).await,
|
||||||
Err(err) => Err(err)
|
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> {
|
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#"
|
let query = r#"
|
||||||
SELECT id, name, device_type, user_id, date_created
|
SELECT id, name, device_type, user_id, date_created
|
||||||
FROM "playbackQueue"
|
FROM "playbackQueue"
|
||||||
@@ -89,19 +90,35 @@ pub mod queue {
|
|||||||
.bind(device_type)
|
.bind(device_type)
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
.await {
|
.await
|
||||||
|
{
|
||||||
Ok(row) => parse_row(&row).await,
|
Ok(row) => parse_row(&row).await,
|
||||||
Err(err) => Err(err)
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn parse_row(row: &PgRow) -> Result<PlaybackQueue, SqlxError> {
|
async fn parse_row(row: &PgRow) -> Result<PlaybackQueue, SqlxError> {
|
||||||
Ok(PlaybackQueue {
|
Ok(PlaybackQueue {
|
||||||
id: row.try_get("id").map_err(|_e| SqlxError::RowNotFound).unwrap(),
|
id: row
|
||||||
name: row.try_get("name").map_err(|_e| SqlxError::RowNotFound).unwrap(),
|
.try_get("id")
|
||||||
device_type: row.try_get("device_type").map_err(|_e| SqlxError::RowNotFound).unwrap(),
|
.map_err(|_e| SqlxError::RowNotFound)
|
||||||
user_id: row.try_get("user_id").map_err(|_e| SqlxError::RowNotFound).unwrap(),
|
.unwrap(),
|
||||||
date_created: row.try_get("date_created").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(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user