tsk-196: Moving SongQueue struct

This commit is contained in:
kdeng00
2025-11-03 13:49:13 -05:00
parent a80e21b918
commit b9fd0cfcc5
2 changed files with 14 additions and 12 deletions
+1 -1
View File
@@ -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>,
} }
} }
+9 -7
View File
@@ -11,13 +11,15 @@ pub mod status {
} }
} }
// TODO: Move this somewhere else at some point pub mod dbtype {
#[derive(Debug, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema)] /// Maps to the songQueue table. Does not contain the data field
pub struct SongQueue { #[derive(Debug, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema)]
pub struct SongQueue {
pub id: uuid::Uuid, pub id: uuid::Uuid,
pub filename: String, pub filename: String,
pub status: String, pub status: String,
pub user_id: uuid::Uuid, pub user_id: uuid::Uuid,
}
} }
pub async fn insert( pub async fn insert(
@@ -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)