Added status to songQueue table #122
@@ -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
|
||||
);
|
||||
|
||||
|
||||
+16
-2
@@ -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<u8>,
|
||||
filename: &String,
|
||||
status: &String,
|
||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||
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,12 @@ pub mod endpoint {
|
||||
file.write_all(&data).unwrap();
|
||||
|
||||
let raw_data: Vec<u8> = 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);
|
||||
|
||||
Reference in New Issue
Block a user