Code formatting
This commit is contained in:
+34
-19
@@ -63,7 +63,6 @@ pub mod status {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mod song_queue {
|
mod song_queue {
|
||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
|
|
||||||
@@ -153,7 +152,10 @@ mod song_queue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_status_of_song_queue(pool: &sqlx::PgPool, id: &uuid::Uuid) -> Result<String, sqlx::Error> {
|
pub async fn get_status_of_song_queue(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<String, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
SELECT id, status FROM "songQueue" WHERE id = $1
|
SELECT id, status FROM "songQueue" WHERE id = $1
|
||||||
@@ -167,16 +169,19 @@ mod song_queue {
|
|||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(row) => {
|
Ok(row) => Ok(row
|
||||||
Ok(row.try_get("status").map_err(|_e| sqlx::Error::RowNotFound).unwrap())
|
.try_get("status")
|
||||||
}
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
Err(_err) => {
|
.unwrap()),
|
||||||
Err(sqlx::Error::RowNotFound)
|
Err(_err) => Err(sqlx::Error::RowNotFound),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_song_queue_status(pool: &sqlx::PgPool, status: &String, id: &uuid::Uuid) -> Result<String, sqlx::Error> {
|
pub async fn update_song_queue_status(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
status: &String,
|
||||||
|
id: &uuid::Uuid,
|
||||||
|
) -> Result<String, sqlx::Error> {
|
||||||
let result = sqlx::query(
|
let result = sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
UPDATE "songQueue" SET status = $1 WHERE id = $2 RETURNING status;
|
UPDATE "songQueue" SET status = $1 WHERE id = $2 RETURNING status;
|
||||||
@@ -191,12 +196,11 @@ mod song_queue {
|
|||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(row) => {
|
Ok(row) => Ok(row
|
||||||
Ok(row.try_get("status").map_err(|_e| sqlx::Error::RowNotFound).unwrap())
|
.try_get("status")
|
||||||
}
|
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||||
Err(_) => {
|
.unwrap()),
|
||||||
Err(sqlx::Error::RowNotFound)
|
Err(_) => Err(sqlx::Error::RowNotFound),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,7 +336,10 @@ pub mod endpoint {
|
|||||||
pub async fn update_song_queue_status(
|
pub async fn update_song_queue_status(
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
axum::Json(payload): axum::Json<super::request::update_status::Request>,
|
axum::Json(payload): axum::Json<super::request::update_status::Request>,
|
||||||
) -> (axum::http::StatusCode, axum::Json<super::response::update_status::Response>) {
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<super::response::update_status::Response>,
|
||||||
|
) {
|
||||||
let mut response = super::response::update_status::Response::default();
|
let mut response = super::response::update_status::Response::default();
|
||||||
|
|
||||||
if super::status::is_valid(&payload.status).await {
|
if super::status::is_valid(&payload.status).await {
|
||||||
@@ -340,12 +347,20 @@ pub mod endpoint {
|
|||||||
if !id.is_nil() {
|
if !id.is_nil() {
|
||||||
match super::song_queue::get_status_of_song_queue(&pool, &id).await {
|
match super::song_queue::get_status_of_song_queue(&pool, &id).await {
|
||||||
Ok(old) => {
|
Ok(old) => {
|
||||||
match super::song_queue::update_song_queue_status(&pool, &payload.status, &id).await {
|
match super::song_queue::update_song_queue_status(
|
||||||
|
&pool,
|
||||||
|
&payload.status,
|
||||||
|
&id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(new) => {
|
Ok(new) => {
|
||||||
response.message = String::from("Successful");
|
response.message = String::from("Successful");
|
||||||
response.data.push(super::response::update_status::ChangedStatus{
|
response
|
||||||
|
.data
|
||||||
|
.push(super::response::update_status::ChangedStatus {
|
||||||
old_status: old,
|
old_status: old,
|
||||||
new_status: new
|
new_status: new,
|
||||||
});
|
});
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -802,7 +802,8 @@ mod tests {
|
|||||||
.body(axum::body::Body::from(payload.to_string()))
|
.body(axum::body::Body::from(payload.to_string()))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await {
|
.await
|
||||||
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let resp = get_resp_data::<
|
let resp = get_resp_data::<
|
||||||
crate::callers::song::response::update_status::Response,
|
crate::callers::song::response::update_status::Response,
|
||||||
@@ -811,8 +812,14 @@ mod tests {
|
|||||||
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
assert_eq!(false, resp.data.is_empty(), "Should not be empty");
|
||||||
let changed_status = &resp.data[0];
|
let changed_status = &resp.data[0];
|
||||||
|
|
||||||
assert_eq!(*old, changed_status.old_status, "Old status does not match");
|
assert_eq!(
|
||||||
assert_eq!(done, changed_status.new_status, "New status does not match");
|
*old, changed_status.old_status,
|
||||||
|
"Old status does not match"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
done, changed_status.new_status,
|
||||||
|
"New status does not match"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
assert!(false, "Error: {:?}", err);
|
assert!(false, "Error: {:?}", err);
|
||||||
|
|||||||
Reference in New Issue
Block a user