tsk-196: Moving SongQueue struct
This commit is contained in:
@@ -53,7 +53,7 @@ pub mod response {
|
|||||||
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<crate::repo::queue::song::SongQueue>,
|
pub data: Vec<crate::repo::queue::song::dbtype::SongQueue>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ pub mod status {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move this somewhere else at some point
|
pub mod dbtype {
|
||||||
|
/// Maps to the songQueue table. Does not contain the data field
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema)]
|
||||||
pub struct SongQueue {
|
pub struct SongQueue {
|
||||||
pub id: uuid::Uuid,
|
pub id: uuid::Uuid,
|
||||||
@@ -19,6 +20,7 @@ pub struct SongQueue {
|
|||||||
pub status: String,
|
pub status: String,
|
||||||
pub user_id: uuid::Uuid,
|
pub user_id: uuid::Uuid,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
@@ -79,7 +81,7 @@ pub async fn update(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_most_recent_and_update(pool: &sqlx::PgPool) -> Result<SongQueue, sqlx::Error> {
|
pub async fn get_most_recent_and_update(pool: &sqlx::PgPool) -> Result<dbtype::SongQueue, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
UPDATE "songQueue"
|
UPDATE "songQueue"
|
||||||
@@ -102,7 +104,7 @@ pub async fn get_most_recent_and_update(pool: &sqlx::PgPool) -> Result<SongQueue
|
|||||||
match result {
|
match result {
|
||||||
Ok(row) => {
|
Ok(row) => {
|
||||||
let user_id_result = row.try_get("user_id");
|
let user_id_result = row.try_get("user_id");
|
||||||
let song_queue = SongQueue {
|
let song_queue = dbtype::SongQueue {
|
||||||
id: row
|
id: row
|
||||||
.try_get("id")
|
.try_get("id")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
@@ -209,7 +211,7 @@ pub async fn link_user_id(
|
|||||||
pub async fn get_song_queue(
|
pub async fn get_song_queue(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<SongQueue, sqlx::Error> {
|
) -> Result<dbtype::SongQueue, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, filename, status, user_id FROM "songQueue" WHERE id = $1
|
SELECT id, filename, status, user_id FROM "songQueue" WHERE id = $1
|
||||||
@@ -225,7 +227,7 @@ pub async fn get_song_queue(
|
|||||||
match result {
|
match result {
|
||||||
Ok(row) => {
|
Ok(row) => {
|
||||||
let user_id_result = row.try_get("user_id");
|
let user_id_result = row.try_get("user_id");
|
||||||
let song_queue = SongQueue {
|
let song_queue = dbtype::SongQueue {
|
||||||
id: row
|
id: row
|
||||||
.try_get("id")
|
.try_get("id")
|
||||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
|
|||||||
Reference in New Issue
Block a user