From 74db93c431ebc02b1dc43ec12714007d005a9704 Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Fri, 21 Nov 2025 16:26:35 +0100 Subject: Update story delete endpoint to use id path to identify story --- src/handlers/admin.rs | 18 ++++-------------- src/handlers/mod.rs | 8 +++----- 2 files changed, 7 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/handlers/admin.rs b/src/handlers/admin.rs index 03c933b..b0863af 100644 --- a/src/handlers/admin.rs +++ b/src/handlers/admin.rs @@ -3,7 +3,7 @@ use std::io::{BufWriter, Write}; use anyhow::Context; use axum::body::Bytes; -use axum::extract::{Multipart, Request, State}; +use axum::extract::{Multipart, Path, Request, State}; use axum::http::{HeaderMap, StatusCode}; use axum::middleware::Next; use axum::response::{IntoResponse, Response}; @@ -126,20 +126,10 @@ pub async fn upload_story( pub async fn delete_story( ctx: Extension, - mut multipart: Multipart, + Path(story_id): Path, ) -> 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()) + Story::delete(&ctx.pool, story_id).await?; + Ok((StatusCode::NO_CONTENT).into_response()) } pub async fn get_stories(ctx: Extension) -> Result { diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index bb5473d..3235f24 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -3,7 +3,7 @@ use tokio::sync::Mutex; use axum::extract::DefaultBodyLimit; use axum::middleware::{self}; -use axum::routing::{get, post}; +use axum::routing::{delete, get, post}; use axum::Router; use sqlx::SqlitePool; use tower_http::add_extension::AddExtensionLayer; @@ -36,10 +36,8 @@ pub async fn router(pool: SqlitePool) -> Router { }; Router::new() - .route( - "/admin/story", - post(upload_story).delete(delete_story).get(get_stories), - ) + .route("/admin/story/:story_id", delete(delete_story)) + .route("/admin/story", post(upload_story).get(get_stories)) .route("/admin/product", get(get_products)) .route("/admin", get(admin_healthcheck)) .layer(middleware::from_fn_with_state( -- cgit v1.2.3