Code formatting
This commit is contained in:
+45
-37
@@ -81,7 +81,7 @@ pub mod request {
|
|||||||
pub mod wipe_data_from_song_queue {
|
pub mod wipe_data_from_song_queue {
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
pub song_queue_id: uuid::Uuid
|
pub song_queue_id: uuid::Uuid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ pub mod response {
|
|||||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
|
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<uuid::Uuid>
|
pub data: Vec<uuid::Uuid>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -474,18 +474,21 @@ mod song_queue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_song_queue(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result<SongQueue, sqlx::Error> {
|
pub async fn get_song_queue(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<SongQueue, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, filename, status FROM "songQueue" WHERE id = $1
|
SELECT id, filename, status FROM "songQueue" WHERE id = $1
|
||||||
"#
|
"#,
|
||||||
)
|
)
|
||||||
.bind(id)
|
.bind(id)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
eprintln!("Error querying data: {:?}", e);
|
eprintln!("Error querying data: {:?}", e);
|
||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(row) => Ok(SongQueue {
|
Ok(row) => Ok(SongQueue {
|
||||||
@@ -506,24 +509,28 @@ mod song_queue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn wipe_data(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result<uuid::Uuid, sqlx::Error> {
|
pub async fn wipe_data(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
UPDATE "songQueue" SET data = NULL WHERE id = $1 RETURNING id;
|
UPDATE "songQueue" SET data = NULL WHERE id = $1 RETURNING id;
|
||||||
"#
|
"#,
|
||||||
)
|
)
|
||||||
.bind(id)
|
.bind(id)
|
||||||
.fetch_one(pool)
|
.fetch_one(pool)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
eprintln!("Error updating record: {:?}", e);
|
eprintln!("Error updating record: {:?}", e);
|
||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(row) => {
|
Ok(row) => Ok(row
|
||||||
Ok(row.try_get("id").map_err(|_e| sqlx::Error::RowNotFound).unwrap())
|
.try_get("id")
|
||||||
}
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
Err(_) => Err(sqlx::Error::RowNotFound)
|
.unwrap()),
|
||||||
|
Err(_) => Err(sqlx::Error::RowNotFound),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -808,25 +815,26 @@ pub mod endpoint {
|
|||||||
pub async fn wipe_data_from_song_queue(
|
pub async fn wipe_data_from_song_queue(
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
axum::Json(payload): axum::Json<super::request::wipe_data_from_song_queue::Request>,
|
axum::Json(payload): axum::Json<super::request::wipe_data_from_song_queue::Request>,
|
||||||
) -> (axum::http::StatusCode, axum::Json<super::response::wipe_data_from_song_queue::Response>,) {
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<super::response::wipe_data_from_song_queue::Response>,
|
||||||
|
) {
|
||||||
let mut response = super::response::wipe_data_from_song_queue::Response::default();
|
let mut response = super::response::wipe_data_from_song_queue::Response::default();
|
||||||
let id = payload.song_queue_id;
|
let id = payload.song_queue_id;
|
||||||
|
|
||||||
match super::song_queue::get_song_queue(&pool, &id).await {
|
match super::song_queue::get_song_queue(&pool, &id).await {
|
||||||
Ok(song_queue) => {
|
Ok(song_queue) => match super::song_queue::wipe_data(&pool, &song_queue.id).await {
|
||||||
match super::song_queue::wipe_data(&pool, &song_queue.id).await {
|
Ok(wiped_id) => {
|
||||||
Ok(wiped_id) => {
|
response.message = String::from("Success");
|
||||||
response.message = String::from("Success");
|
response.data.push(wiped_id);
|
||||||
response.data.push(wiped_id);
|
|
||||||
|
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
||||||
|
}
|
||||||
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
response.message = err.to_string();
|
response.message = err.to_string();
|
||||||
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
||||||
|
|||||||
+2
-2
@@ -75,8 +75,8 @@ pub mod init {
|
|||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
crate::callers::endpoints::QUEUESONGDATAWIPE,
|
crate::callers::endpoints::QUEUESONGDATAWIPE,
|
||||||
patch(crate::callers::song::endpoint::wipe_data_from_song_queue)
|
patch(crate::callers::song::endpoint::wipe_data_from_song_queue),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
crate::callers::endpoints::QUEUEMETADATA,
|
crate::callers::endpoints::QUEUEMETADATA,
|
||||||
post(crate::callers::metadata::endpoint::queue_metadata),
|
post(crate::callers::metadata::endpoint::queue_metadata),
|
||||||
|
|||||||
Reference in New Issue
Block a user