Added status to songQueue table (#122)
* Added status to songQueue table * Added status * Formatting * Removed failed option for the status field for now
This commit was merged in pull request #122.
This commit is contained in:
@@ -5,6 +5,7 @@ CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
|||||||
CREATE TABLE IF NOT EXISTS "songQueue" (
|
CREATE TABLE IF NOT EXISTS "songQueue" (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
filename TEXT NOT NULL,
|
filename TEXT NOT NULL,
|
||||||
|
status TEXT CHECK (status IN ('pending', 'processing', 'done')),
|
||||||
data BYTEA NOT NULL
|
data BYTEA NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+16
-2
@@ -20,6 +20,13 @@ pub mod response {
|
|||||||
mod song_queue {
|
mod song_queue {
|
||||||
use sqlx::Row;
|
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)]
|
#[derive(Debug, serde::Serialize, sqlx::FromRow)]
|
||||||
pub struct InsertedData {
|
pub struct InsertedData {
|
||||||
pub id: uuid::Uuid,
|
pub id: uuid::Uuid,
|
||||||
@@ -29,14 +36,16 @@ mod song_queue {
|
|||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
data: &Vec<u8>,
|
data: &Vec<u8>,
|
||||||
filename: &String,
|
filename: &String,
|
||||||
|
status: &String,
|
||||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
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(data)
|
||||||
.bind(filename)
|
.bind(filename)
|
||||||
|
.bind(status)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
@@ -88,7 +97,12 @@ pub mod endpoint {
|
|||||||
file.write_all(&data).unwrap();
|
file.write_all(&data).unwrap();
|
||||||
|
|
||||||
let raw_data: Vec<u8> = data.to_vec();
|
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
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
results.push(queue_repo);
|
results.push(queue_repo);
|
||||||
|
|||||||
Reference in New Issue
Block a user