From db7350b550327fe8dc75059521f8da9ba6e0130b Mon Sep 17 00:00:00 2001 From: KD Date: Thu, 24 Apr 2025 21:11:45 -0400 Subject: [PATCH] Added status to songQueue table (#122) * Added status to songQueue table * Added status * Formatting * Removed failed option for the status field for now --- migrations/20250420185217_init_migration.sql | 1 + src/callers/song.rs | 22 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/migrations/20250420185217_init_migration.sql b/migrations/20250420185217_init_migration.sql index 57615c4..6ea4c60 100644 --- a/migrations/20250420185217_init_migration.sql +++ b/migrations/20250420185217_init_migration.sql @@ -5,6 +5,7 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto; CREATE TABLE IF NOT EXISTS "songQueue" ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), filename TEXT NOT NULL, + status TEXT CHECK (status IN ('pending', 'processing', 'done')), data BYTEA NOT NULL ); diff --git a/src/callers/song.rs b/src/callers/song.rs index a98d0a7..0f89887 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -20,6 +20,13 @@ pub mod response { mod song_queue { use sqlx::Row; + pub mod status { + pub const PENDING: &str = "pending"; + // Will be used later on + pub const _PROCESSING: &str = "processing"; + pub const _DONE: &str = "done"; + } + #[derive(Debug, serde::Serialize, sqlx::FromRow)] pub struct InsertedData { pub id: uuid::Uuid, @@ -29,14 +36,16 @@ mod song_queue { pool: &sqlx::PgPool, data: &Vec, filename: &String, + status: &String, ) -> Result { let result = sqlx::query( r#" - INSERT INTO "songQueue" (data, filename) VALUES($1, $2) RETURNING id; + INSERT INTO "songQueue" (data, filename, status) VALUES($1, $2, $3) RETURNING id; "#, ) .bind(data) .bind(filename) + .bind(status) .fetch_one(pool) .await .map_err(|e| { @@ -88,9 +97,14 @@ pub mod endpoint { file.write_all(&data).unwrap(); let raw_data: Vec = data.to_vec(); - let queue_repo = song_queue::insert(&pool, &raw_data, &file_name) - .await - .unwrap(); + let queue_repo = song_queue::insert( + &pool, + &raw_data, + &file_name, + &song_queue::status::PENDING.to_string(), + ) + .await + .unwrap(); results.push(queue_repo); }