From 12b307a9c8937c256cad8b1e59e03cec7c69b7fd Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 24 Apr 2025 20:58:59 -0400 Subject: [PATCH 1/4] Added status to songQueue table --- migrations/20250420185217_init_migration.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/migrations/20250420185217_init_migration.sql b/migrations/20250420185217_init_migration.sql index 57615c4..cdc7b34 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', 'failed')), data BYTEA NOT NULL ); -- 2.47.3 From 0faf496641019ec22bf1d946787ae349d9464d58 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 24 Apr 2025 21:06:01 -0400 Subject: [PATCH 2/4] Added status --- src/callers/song.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index a98d0a7..8af17b8 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,7 +97,7 @@ 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) + let queue_repo = song_queue::insert(&pool, &raw_data, &file_name, &song_queue::status::PENDING.to_string()) .await .unwrap(); results.push(queue_repo); -- 2.47.3 From 397e10b3b351d611e1f0c887edab1bbded677029 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 24 Apr 2025 21:06:24 -0400 Subject: [PATCH 3/4] Formatting --- src/callers/song.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/callers/song.rs b/src/callers/song.rs index 8af17b8..0f89887 100644 --- a/src/callers/song.rs +++ b/src/callers/song.rs @@ -97,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, &song_queue::status::PENDING.to_string()) - .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); } -- 2.47.3 From cc4472c5549ee49773b6853537c0e71191040e79 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 24 Apr 2025 21:09:49 -0400 Subject: [PATCH 4/4] Removed failed option for the status field for now --- migrations/20250420185217_init_migration.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/20250420185217_init_migration.sql b/migrations/20250420185217_init_migration.sql index cdc7b34..6ea4c60 100644 --- a/migrations/20250420185217_init_migration.sql +++ b/migrations/20250420185217_init_migration.sql @@ -5,7 +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', 'failed')), + status TEXT CHECK (status IN ('pending', 'processing', 'done')), data BYTEA NOT NULL ); -- 2.47.3