From 680867b4bb5e2708f02fc3f8c21c3563975c44c7 Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Thu, 7 Nov 2024 18:35:27 +0100 Subject: Feat: Add admin API route to delete story by product id --- src/handlers/admin.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/handlers/admin.rs') diff --git a/src/handlers/admin.rs b/src/handlers/admin.rs index 7c016dd..3d16b32 100644 --- a/src/handlers/admin.rs +++ b/src/handlers/admin.rs @@ -132,3 +132,21 @@ pub async fn upload_story( .await?; Ok((StatusCode::CREATED, Json(story)).into_response()) } + +pub async fn delete_story( + ctx: Extension, + mut multipart: Multipart, +) -> Result { + if let Some(field) = multipart.next_field().await? { + if let Some(label) = field.name() { + if label == "id" { + let pid = field.text().await?.parse::()?; + Story::delete(&ctx.pool, pid).await?; + return Ok((StatusCode::NO_CONTENT).into_response()); + } + return Ok(StatusCode::BAD_REQUEST.into_response()); + } + return Ok(StatusCode::BAD_REQUEST.into_response()); + } + Ok(StatusCode::BAD_REQUEST.into_response()) +} -- cgit v1.2.3