Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f48c7ee99c
|
||
|
|
64c6a7f6b5
|
||
|
|
4fdcd80db2
|
||
|
|
d249c34fb4
|
||
|
|
58682af84a
|
||
|
|
6ca17357dc
|
||
|
|
b668dc4abb
|
||
|
|
d2b9567c15
|
||
|
|
8a0e88c215
|
||
|
|
ed82e59a26
|
||
|
|
4ee0ba59fd
|
||
|
|
4403f3c7d2
|
||
|
|
980d2557a2
|
||
|
|
864447aa16
|
||
|
|
9b51442841
|
No files matched your search
@@ -5,6 +5,8 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||
CREATE TABLE IF NOT EXISTS "songQueue" (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
filename TEXT NOT NULL,
|
||||
-- TODO: Make it uppercase and check other areas of soaricarus to make
|
||||
-- sure it is consistent
|
||||
status TEXT CHECK (status IN ('pending', 'ready', 'processing', 'done')),
|
||||
user_id UUID NULL
|
||||
);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
-- Add migration script here
|
||||
CREATE TABLE IF NOT EXISTS "playbackQueue" (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name TEXT NOT NULL,
|
||||
device_type TEXT CHECK (device_type IN ('BROWSER', 'MOBILE')),
|
||||
user_id UUID NOT NULL,
|
||||
date_created timestamptz DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "playbackQueueItem" (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
queue_index INT NOT NULL,
|
||||
song_id UUID NOT NULL,
|
||||
playback_queue_id UUID NOT NULL,
|
||||
date_created timestamptz DEFAULT now()
|
||||
);
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod coverart;
|
||||
pub mod playback;
|
||||
pub mod queue;
|
||||
pub mod song;
|
||||
|
||||
@@ -14,10 +15,13 @@ pub mod endpoints {
|
||||
pub const CREATECOVERART: &str = "/api/v2/coverart";
|
||||
pub const GETCOVERART: &str = "/api/v2/coverart";
|
||||
pub const DOWNLOADCOVERART: &str = "/api/v2/coverart/download/{id}";
|
||||
|
||||
pub const CREATEPLAYBACKQUEUE: &str = "/api/v2/playback/queue";
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
pub const SUCCESSFUL: &str = "SUCCESSFUL";
|
||||
pub const INVALID: &str = "INVALID";
|
||||
}
|
||||
|
||||
/// Basic handler that responds with a static string
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
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)]
|
||||
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, utoipa::ToSchema)]
|
||||
pub struct CreatePlaybackQueueRequest {
|
||||
pub name: String,
|
||||
pub device_type: String,
|
||||
pub user_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
impl CreatePlaybackQueueRequest {
|
||||
pub fn is_valid(&self) -> bool {
|
||||
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 {
|
||||
matches!(
|
||||
self.device_type.as_str(),
|
||||
super::super::PLAYBACK_QUEUE_DEVICE_TYPE_BROWSER
|
||||
| super::super::PLAYBACK_QUEUE_DEVICE_TYPE_MOBILE
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
pub mod create_playback_queue {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct CreatePlaybackQueueResponse {
|
||||
pub message: String,
|
||||
pub data: Vec<super::super::PlaybackQueue>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod endpoint {
|
||||
use axum::{Extension, Json, http};
|
||||
use http::StatusCode;
|
||||
|
||||
use crate::repo::playback::queue as playback_repo;
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = super::super::super::endpoints::CREATEPLAYBACKQUEUE,
|
||||
request_body(
|
||||
content = super::request::create_playback_queue::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)
|
||||
)
|
||||
)]
|
||||
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_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
|
||||
response.message = "Already created".to_string();
|
||||
(StatusCode::OK, Json(response))
|
||||
} 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::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::CREATED, Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, Json(response))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -5,16 +5,20 @@ use tower_http::timeout::TimeoutLayer;
|
||||
use utoipa::OpenApi;
|
||||
|
||||
use crate::callers::coverart as coverart_caller;
|
||||
use crate::callers::playback::queue as playback_caller;
|
||||
use crate::callers::queue::coverart as coverart_queue_callers;
|
||||
use crate::callers::queue::metadata as metadata_queue_caller;
|
||||
use crate::callers::queue::song as song_queue_callers;
|
||||
use crate::callers::song as song_caller;
|
||||
|
||||
use coverart_caller::endpoint as coverart_endpoints;
|
||||
use coverart_caller::response as coverart_responses;
|
||||
use coverart_queue_callers::endpoint as coverart_queue_endpoints;
|
||||
use coverart_queue_callers::response as coverart_queue_responses;
|
||||
use metadata_queue_caller::endpoint as metadata_queue_endpoints;
|
||||
use metadata_queue_caller::response as metadata_queue_responses;
|
||||
use playback_caller::endpoint as playback_endpoints;
|
||||
use playback_caller::response as playback_responses;
|
||||
use song_caller::endpoint as song_endpoints;
|
||||
use song_caller::response as song_responses;
|
||||
use song_queue_callers::endpoint as song_queue_endpoints;
|
||||
@@ -73,14 +77,14 @@ mod cors {
|
||||
song_endpoints::delete_song, coverart_queue_endpoints::queue, coverart_queue_endpoints::link, coverart_queue_endpoints::fetch_coverart_no_data,
|
||||
coverart_queue_endpoints::fetch_coverart_with_data, coverart_endpoints::create_coverart, coverart_queue_endpoints::wipe_data_from_coverart_queue,
|
||||
coverart_endpoints::get_coverart, coverart_endpoints::download_coverart,
|
||||
metadata_queue_endpoints::queue_metadata, metadata_queue_endpoints::fetch_metadata),
|
||||
metadata_queue_endpoints::queue_metadata, metadata_queue_endpoints::fetch_metadata, playback_endpoints::create_playback_queue),
|
||||
components(schemas(song_queue_callers::response::song_queue::Response, song_queue_callers::response::link_user_id::Response, song_queue_callers::response::fetch_queue_song::Response,
|
||||
song_queue_responses::update_status::Response, song_queue_callers::response::update_song_queue::Response, song_responses::create_metadata::Response,
|
||||
song_queue_callers::response::wipe_data_from_song_queue::Response, song_responses::get_songs::Response, song_responses::delete_song::Response,
|
||||
coverart_queue_responses::queue::Response, coverart_queue_responses::link::Response, coverart_queue_responses::fetch_coverart_no_data::Response,
|
||||
coverart_queue_responses::fetch_coverart_with_data::Response, coverart_responses::create_coverart::Response,
|
||||
coverart_queue_responses::wipe_data_from_coverart_queue::Response, coverart_responses::get_coverart::Response,
|
||||
metadata_queue_responses::queue_metadata::Response, metadata_queue_responses::fetch_metadata::Response)),
|
||||
metadata_queue_responses::queue_metadata::Response, metadata_queue_responses::fetch_metadata::Response, playback_responses::create_playback_queue::CreatePlaybackQueueResponse)),
|
||||
tags(
|
||||
(name = "soaricarus API", description = "Web API to manage music")
|
||||
)
|
||||
@@ -227,6 +231,10 @@ pub async fn routes() -> axum::Router {
|
||||
crate::callers::endpoints::GETALLSONGS,
|
||||
get(crate::callers::song::endpoint::get_all_songs),
|
||||
)
|
||||
.route(
|
||||
crate::callers::endpoints::CREATEPLAYBACKQUEUE,
|
||||
post(playback_endpoints::create_playback_queue),
|
||||
)
|
||||
.layer(cors::configure_cors().await)
|
||||
}
|
||||
|
||||
|
||||
+113
-30
@@ -117,13 +117,15 @@ mod tests {
|
||||
}
|
||||
|
||||
mod util {
|
||||
use axum::response;
|
||||
|
||||
pub async fn resp_to_bytes(
|
||||
response: axum::response::Response,
|
||||
response: response::Response,
|
||||
) -> Result<axum::body::Bytes, axum::Error> {
|
||||
axum::body::to_bytes(response.into_body(), usize::MAX).await
|
||||
}
|
||||
|
||||
pub async fn get_resp_data<Data>(response: axum::response::Response) -> Data
|
||||
pub async fn get_resp_data<Data>(response: response::Response) -> Data
|
||||
where
|
||||
Data: for<'a> serde::Deserialize<'a>,
|
||||
{
|
||||
@@ -137,16 +139,12 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn token_fields() -> (String, String, String) {
|
||||
(
|
||||
String::from("What a twist!"),
|
||||
String::from("soaricarus_test"),
|
||||
String::from("soaricarus"),
|
||||
)
|
||||
}
|
||||
|
||||
mod test_data {
|
||||
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
|
||||
|
||||
pub const DEVICE_TYPE: &str = "BROWSER";
|
||||
pub const NAME: &str = "DougDimmaDome Browser Queue";
|
||||
|
||||
pub async fn test_token() -> Result<String, josekit::JoseError> {
|
||||
let key: String = sienvy::environment::get_secret_main_key().value;
|
||||
let (message, issuer, audience) = token_fields();
|
||||
@@ -164,8 +162,17 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn token_fields() -> (String, String, String) {
|
||||
(
|
||||
"What a twist!".to_string(),
|
||||
"soaricarus_test".to_string(),
|
||||
"soaricarus".to_string(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn bearer_auth() -> String {
|
||||
let token = match test_token().await {
|
||||
let token = match test_data::test_token().await {
|
||||
Ok(access_token) => access_token,
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {err:?}");
|
||||
@@ -444,6 +451,31 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_playback_queue(
|
||||
app: &axum::Router,
|
||||
name: &str,
|
||||
device_type: &str,
|
||||
user_id: &uuid::Uuid,
|
||||
) -> Result<axum::response::Response, axum::http::Error> {
|
||||
let uri = soaricarus_api::callers::endpoints::CREATEPLAYBACKQUEUE;
|
||||
let payload =
|
||||
super::payload_data::create_playback_queue(name, device_type, user_id).await;
|
||||
match run_post(
|
||||
Some(ReqBody::Json(payload)),
|
||||
uri,
|
||||
axum::http::Method::POST,
|
||||
true,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(request) => match app.clone().oneshot(request).await {
|
||||
Ok(response) => Ok(response),
|
||||
Err(err) => Err(axum::http::Error::from(err)),
|
||||
},
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ReqBody {
|
||||
Json(serde_json::Value),
|
||||
Multipart((String, String)),
|
||||
@@ -633,7 +665,7 @@ mod tests {
|
||||
let song_queue_id = resp.data[0];
|
||||
assert_eq!(false, song_queue_id.is_nil(), "Should not be empty");
|
||||
|
||||
let user_id = super::TEST_USER_ID;
|
||||
let user_id = super::test_data::TEST_USER_ID;
|
||||
|
||||
match super::request::song_queue_link_req(&app, &song_queue_id, &user_id).await
|
||||
{
|
||||
@@ -779,8 +811,11 @@ mod tests {
|
||||
}
|
||||
|
||||
pub mod payload_data {
|
||||
pub async fn queue_metadata(song_queue_id: &uuid::Uuid) -> serde_json::Value {
|
||||
serde_json::json!(
|
||||
use serde_json::Value as JsonValue;
|
||||
use serde_json::json;
|
||||
|
||||
pub async fn queue_metadata(song_queue_id: &uuid::Uuid) -> JsonValue {
|
||||
json!(
|
||||
{
|
||||
"song_queue_id": song_queue_id,
|
||||
"album" : "I",
|
||||
@@ -797,11 +832,8 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn create_song(
|
||||
song_queue_id: &uuid::Uuid,
|
||||
user_id: &uuid::Uuid,
|
||||
) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
pub async fn create_song(song_queue_id: &uuid::Uuid, user_id: &uuid::Uuid) -> JsonValue {
|
||||
json!({
|
||||
"title" : "Hypocrite Like The Rest",
|
||||
"artist" : "Kuoth",
|
||||
"album_artist": "Kuoth",
|
||||
@@ -819,11 +851,23 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn create_playback_queue(
|
||||
name: &str,
|
||||
device_type: &str,
|
||||
user_id: &uuid::Uuid,
|
||||
) -> JsonValue {
|
||||
json!({
|
||||
"name": name,
|
||||
"device_type": device_type,
|
||||
"user_id": user_id
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn link_user_to_queued_song(
|
||||
song_queue_id: &uuid::Uuid,
|
||||
user_id: &uuid::Uuid,
|
||||
) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
) -> JsonValue {
|
||||
json!({
|
||||
"song_queue_id": song_queue_id,
|
||||
"user_id": user_id
|
||||
})
|
||||
@@ -832,8 +876,8 @@ mod tests {
|
||||
pub async fn link_queued_coverart_to_queued_song(
|
||||
song_queue_id: &uuid::Uuid,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
) -> JsonValue {
|
||||
json!({
|
||||
"song_queue_id": song_queue_id,
|
||||
"coverart_id": coverart_queue_id
|
||||
})
|
||||
@@ -842,17 +886,15 @@ mod tests {
|
||||
pub async fn create_coverart(
|
||||
song_id: &uuid::Uuid,
|
||||
coverart_queue_id: &uuid::Uuid,
|
||||
) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
) -> JsonValue {
|
||||
json!({
|
||||
"song_id": song_id,
|
||||
"coverart_queue_id": coverart_queue_id
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn update_song_queue_status_to_ready(
|
||||
song_queue_id: &uuid::Uuid,
|
||||
) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
pub async fn update_song_queue_status_to_ready(song_queue_id: &uuid::Uuid) -> JsonValue {
|
||||
json!({
|
||||
"id": song_queue_id,
|
||||
"status": soaricarus_api::repo::queue::song::status::READY
|
||||
})
|
||||
@@ -926,7 +968,7 @@ mod tests {
|
||||
assert_eq!(false, resp.data[0].is_nil(), "Should not be empty");
|
||||
|
||||
let song_queue_id = &resp.data[0];
|
||||
let user_id = TEST_USER_ID;
|
||||
let user_id = test_data::TEST_USER_ID;
|
||||
println!("User Id: {user_id:?}");
|
||||
|
||||
match request::song_queue_link_req(&app, &song_queue_id, &user_id).await {
|
||||
@@ -2036,6 +2078,8 @@ mod tests {
|
||||
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||
}
|
||||
|
||||
// NOTE: This was probably done so the tests in this module run after
|
||||
// all the other tests finished
|
||||
pub mod zzz_after_song_queue {
|
||||
use futures::StreamExt;
|
||||
use tower::ServiceExt;
|
||||
@@ -2592,5 +2636,44 @@ mod tests {
|
||||
|
||||
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_create_playback_queue() {
|
||||
let tm_pool = super::db_mgr::get_pool().await.unwrap();
|
||||
let db_name = super::db_mgr::generate_db_name().await;
|
||||
|
||||
match super::db_mgr::create_database(&tm_pool, &db_name).await {
|
||||
Ok(_) => {
|
||||
println!("Success");
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
}
|
||||
}
|
||||
|
||||
let pool = super::db_mgr::connect_to_db(&db_name).await.unwrap();
|
||||
super::db_mgr::migrations(&pool).await;
|
||||
|
||||
let app = super::init::app(pool).await;
|
||||
let user_id = super::test_data::TEST_USER_ID;
|
||||
let device_type = super::test_data::DEVICE_TYPE;
|
||||
let name = super::test_data::NAME;
|
||||
|
||||
match super::request::create_playback_queue(&app, name, device_type, &user_id).await {
|
||||
Ok(response) => {
|
||||
let resp = super::util::get_resp_data::<
|
||||
soaricarus_api::callers::playback::queue::response::create_playback_queue::CreatePlaybackQueueResponse
|
||||
>(response)
|
||||
.await;
|
||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
assert!(false, "Error: {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
let _ = super::db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod coverart;
|
||||
pub mod playback;
|
||||
pub mod queue;
|
||||
pub mod song;
|
||||
@@ -0,0 +1,76 @@
|
||||
pub mod queue {
|
||||
use sqlx::{PgPool, Row};
|
||||
// use sqlx::postgres::PgRow;
|
||||
use crate::callers::playback::queue::PlaybackQueue;
|
||||
use sqlx::Error as SqlxError;
|
||||
|
||||
pub async fn create_queue(
|
||||
pool: &PgPool,
|
||||
playback_queue: &PlaybackQueue,
|
||||
) -> Result<(uuid::Uuid, time::OffsetDateTime), 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> {
|
||||
let query = r#"
|
||||
SELECT id FROM "playbackQueue"
|
||||
WHERE device_type = $1 AND user_id = $2;
|
||||
"#;
|
||||
|
||||
match sqlx::query(query)
|
||||
.bind(device_type)
|
||||
.bind(user_id)
|
||||
.execute(pool)
|
||||
.await
|
||||
{
|
||||
Ok(row) => {
|
||||
let rows_affected = row.rows_affected();
|
||||
Ok(rows_affected > 0)
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
})
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
-- Add migration script here
|
||||
CREATE TABLE IF NOT EXISTS "playbackQueue" (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name TEXT NOT NULL,
|
||||
device_type TEXT CHECK (device_type IN ('BROWSER', 'MOBILE')),
|
||||
user_id UUID NOT NULL,
|
||||
date_created timestamptz DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "playbackQueueItem" (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
queue_index INT NOT NULL,
|
||||
song_id UUID NOT NULL,
|
||||
playback_queue_id UUID NOT NULL,
|
||||
date_created timestamptz DEFAULT now()
|
||||
);
|
||||
Reference in new issue
Block a user