Code formatting

This commit is contained in:
kdeng00
2025-05-26 16:50:42 -04:00
parent 570ebb2661
commit c7809a44cf
2 changed files with 70 additions and 44 deletions
+17 -15
View File
@@ -42,7 +42,7 @@ pub mod request {
pub mod wipe_data_from_coverart_queue { pub mod wipe_data_from_coverart_queue {
#[derive(Debug, serde::Deserialize, serde::Serialize)] #[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Request { pub struct Request {
pub coverart_queue_id: uuid::Uuid pub coverart_queue_id: uuid::Uuid,
} }
} }
} }
@@ -262,11 +262,14 @@ pub mod db {
} }
} }
pub async fn wipe_data(pool: &sqlx::PgPool, coverart_queue_id: &uuid::Uuid) -> Result<uuid::Uuid, sqlx::Error> { pub async fn wipe_data(
pool: &sqlx::PgPool,
coverart_queue_id: &uuid::Uuid,
) -> Result<uuid::Uuid, sqlx::Error> {
let result = sqlx::query( let result = sqlx::query(
r#" r#"
UPDATE "coverartQueue" SET data = NULL WHERE id = $1 RETURNING id; UPDATE "coverartQueue" SET data = NULL WHERE id = $1 RETURNING id;
"# "#,
) )
.bind(coverart_queue_id) .bind(coverart_queue_id)
.fetch_one(pool) .fetch_one(pool)
@@ -276,12 +279,11 @@ pub mod db {
}); });
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(_) => { .unwrap()),
Err(sqlx::Error::RowNotFound) Err(_) => Err(sqlx::Error::RowNotFound),
}
} }
} }
} }
@@ -547,8 +549,10 @@ pub mod endpoint {
} }
} }
pub async fn wipe_data_from_coverart_queue(axum::Extension(pool): axum::Extension<sqlx::PgPool>, pub async fn wipe_data_from_coverart_queue(
axum::Json(payload): axum::Json<super::request::wipe_data_from_coverart_queue::Request>,) -> ( axum::Extension(pool): axum::Extension<sqlx::PgPool>,
axum::Json(payload): axum::Json<super::request::wipe_data_from_coverart_queue::Request>,
) -> (
axum::http::StatusCode, axum::http::StatusCode,
axum::Json<super::response::wipe_data_from_coverart_queue::Response>, axum::Json<super::response::wipe_data_from_coverart_queue::Response>,
) { ) {
@@ -556,8 +560,7 @@ pub mod endpoint {
let coverart_queue_id = payload.coverart_queue_id; let coverart_queue_id = payload.coverart_queue_id;
match super::db::get_coverart_queue_with_id(&pool, &coverart_queue_id).await { match super::db::get_coverart_queue_with_id(&pool, &coverart_queue_id).await {
Ok(coverart_queue) => { Ok(coverart_queue) => match super::db::wipe_data(&pool, &coverart_queue.id).await {
match super::db::wipe_data(&pool, &coverart_queue.id).await {
Ok(id) => { Ok(id) => {
response.message = String::from("Success"); response.message = String::from("Success");
response.data.push(id); response.data.push(id);
@@ -567,8 +570,7 @@ pub mod endpoint {
response.message = err.to_string(); response.message = err.to_string();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response)) (axum::http::StatusCode::BAD_REQUEST, 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))
+32 -8
View File
@@ -101,8 +101,9 @@ pub mod init {
crate::callers::endpoints::QUEUECOVERARTLINK, crate::callers::endpoints::QUEUECOVERARTLINK,
patch(crate::callers::coverart::endpoint::link), patch(crate::callers::coverart::endpoint::link),
) )
.route(crate::callers::endpoints::QUEUECOVERARTDATAWIPE, .route(
patch(crate::callers::coverart::endpoint::wipe_data_from_coverart_queue) crate::callers::endpoints::QUEUECOVERARTDATAWIPE,
patch(crate::callers::coverart::endpoint::wipe_data_from_coverart_queue),
) )
.route( .route(
crate::callers::endpoints::CREATESONG, crate::callers::endpoints::CREATESONG,
@@ -371,8 +372,11 @@ mod tests {
app.clone().oneshot(req).await app.clone().oneshot(req).await
} }
async fn create_coverart_req(
async fn create_coverart_req(app: &axum::Router, song_id: &uuid::Uuid, coverart_id: &uuid::Uuid) -> Result<axum::response::Response, std::convert::Infallible> { app: &axum::Router,
song_id: &uuid::Uuid,
coverart_id: &uuid::Uuid,
) -> Result<axum::response::Response, std::convert::Infallible> {
let payload = serde_json::json!({ let payload = serde_json::json!({
"song_id": song_id, "song_id": song_id,
"coverart_queue_id": coverart_id "coverart_queue_id": coverart_id
@@ -1472,7 +1476,13 @@ mod tests {
"Should not be empty" "Should not be empty"
); );
match create_coverart_req(&app, &song_id, &resp_coverart_id).await { match create_coverart_req(
&app,
&song_id,
&resp_coverart_id,
)
.await
{
Ok(response) => { Ok(response) => {
let resp = get_resp_data::< let resp = get_resp_data::<
crate::callers::coverart::response::create_coverart::Response, crate::callers::coverart::response::create_coverart::Response,
@@ -1485,7 +1495,11 @@ mod tests {
); );
} }
Err(err) => { Err(err) => {
assert!(false, "Error: {:?}", err); assert!(
false,
"Error: {:?}",
err
);
} }
} }
} }
@@ -1781,7 +1795,13 @@ mod tests {
"Should not be empty" "Should not be empty"
); );
match create_coverart_req(&app, &song_id, &resp_coverart_id).await { match create_coverart_req(
&app,
&song_id,
&resp_coverart_id,
)
.await
{
Ok(response) => { Ok(response) => {
let resp = get_resp_data::< let resp = get_resp_data::<
crate::callers::coverart::response::create_coverart::Response, crate::callers::coverart::response::create_coverart::Response,
@@ -1822,7 +1842,11 @@ mod tests {
} }
} }
Err(err) => { Err(err) => {
assert!(false, "Error: {:?}", err); assert!(
false,
"Error: {:?}",
err
);
} }
} }
} }