Wipe data from coverart queue #136
+37
-35
@@ -42,7 +42,7 @@ pub mod request {
|
||||
pub mod wipe_data_from_coverart_queue {
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
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(
|
||||
r#"
|
||||
UPDATE "coverartQueue" SET data = NULL WHERE id = $1 RETURNING id;
|
||||
"#
|
||||
)
|
||||
.bind(coverart_queue_id)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
eprintln!("Error updating query: {:?}", e);
|
||||
});
|
||||
"#,
|
||||
)
|
||||
.bind(coverart_queue_id)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
eprintln!("Error updating query: {:?}", e);
|
||||
});
|
||||
|
||||
match result {
|
||||
Ok(row) => {
|
||||
Ok(row.try_get("id").map_err(|_e| sqlx::Error::RowNotFound).unwrap())
|
||||
}
|
||||
Err(_) => {
|
||||
Err(sqlx::Error::RowNotFound)
|
||||
}
|
||||
Ok(row) => Ok(row
|
||||
.try_get("id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap()),
|
||||
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>,
|
||||
axum::Json(payload): axum::Json<super::request::wipe_data_from_coverart_queue::Request>,) -> (
|
||||
pub async fn wipe_data_from_coverart_queue(
|
||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||
axum::Json(payload): axum::Json<super::request::wipe_data_from_coverart_queue::Request>,
|
||||
) -> (
|
||||
axum::http::StatusCode,
|
||||
axum::Json<super::response::wipe_data_from_coverart_queue::Response>,
|
||||
) {
|
||||
let mut response = super::response::wipe_data_from_coverart_queue::Response::default();
|
||||
let coverart_queue_id = payload.coverart_queue_id;
|
||||
) {
|
||||
let mut response = super::response::wipe_data_from_coverart_queue::Response::default();
|
||||
let coverart_queue_id = payload.coverart_queue_id;
|
||||
|
||||
match super::db::get_coverart_queue_with_id(&pool, &coverart_queue_id).await {
|
||||
Ok(coverart_queue) => {
|
||||
match super::db::wipe_data(&pool, &coverart_queue.id).await {
|
||||
Ok(id) => {
|
||||
response.message = String::from("Success");
|
||||
response.data.push(id);
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
response.message = err.to_string();
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
}
|
||||
}
|
||||
match super::db::get_coverart_queue_with_id(&pool, &coverart_queue_id).await {
|
||||
Ok(coverart_queue) => match super::db::wipe_data(&pool, &coverart_queue.id).await {
|
||||
Ok(id) => {
|
||||
response.message = String::from("Success");
|
||||
response.data.push(id);
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
Err(err) => {
|
||||
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,
|
||||
patch(crate::callers::coverart::endpoint::link),
|
||||
)
|
||||
.route(crate::callers::endpoints::QUEUECOVERARTDATAWIPE,
|
||||
patch(crate::callers::coverart::endpoint::wipe_data_from_coverart_queue)
|
||||
)
|
||||
.route(
|
||||
crate::callers::endpoints::QUEUECOVERARTDATAWIPE,
|
||||
patch(crate::callers::coverart::endpoint::wipe_data_from_coverart_queue),
|
||||
)
|
||||
.route(
|
||||
crate::callers::endpoints::CREATESONG,
|
||||
post(crate::callers::song::endpoint::create_metadata),
|
||||
@@ -371,8 +372,11 @@ mod tests {
|
||||
app.clone().oneshot(req).await
|
||||
}
|
||||
|
||||
|
||||
async fn create_coverart_req(app: &axum::Router, song_id: &uuid::Uuid, coverart_id: &uuid::Uuid) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||
async fn create_coverart_req(
|
||||
app: &axum::Router,
|
||||
song_id: &uuid::Uuid,
|
||||
coverart_id: &uuid::Uuid,
|
||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||
let payload = serde_json::json!({
|
||||
"song_id": song_id,
|
||||
"coverart_queue_id": coverart_id
|
||||
@@ -1472,7 +1476,13 @@ mod tests {
|
||||
"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) => {
|
||||
let resp = get_resp_data::<
|
||||
crate::callers::coverart::response::create_coverart::Response,
|
||||
@@ -1485,7 +1495,11 @@ mod tests {
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
assert!(
|
||||
false,
|
||||
"Error: {:?}",
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1781,7 +1795,13 @@ mod tests {
|
||||
"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) => {
|
||||
let resp = get_resp_data::<
|
||||
crate::callers::coverart::response::create_coverart::Response,
|
||||
@@ -1822,7 +1842,11 @@ mod tests {
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
assert!(false, "Error: {:?}", err);
|
||||
assert!(
|
||||
false,
|
||||
"Error: {:?}",
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user