Code formatting
This commit is contained in:
+37
-35
@@ -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,26 +262,28 @@ 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)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
eprintln!("Error updating query: {:?}", e);
|
eprintln!("Error updating query: {:?}", 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(_) => {
|
.unwrap()),
|
||||||
Err(sqlx::Error::RowNotFound)
|
Err(_) => Err(sqlx::Error::RowNotFound),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,32 +549,32 @@ 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>,
|
||||||
) {
|
) {
|
||||||
let mut response = super::response::wipe_data_from_coverart_queue::Response::default();
|
let mut response = super::response::wipe_data_from_coverart_queue::Response::default();
|
||||||
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);
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
response.message = err.to_string();
|
|
||||||
(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::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(axum::http::StatusCode::NOT_FOUND, axum::Json(response))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-9
@@ -101,9 +101,10 @@ 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,
|
||||||
post(crate::callers::song::endpoint::create_metadata),
|
post(crate::callers::song::endpoint::create_metadata),
|
||||||
@@ -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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user