From 5baff54cb9cbc660a3588544fef5aef641ec37ff Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Mon, 4 May 2026 14:24:48 +0200 Subject: [PATCH] feat(presentation): add DELETE /api/reviews/:id handler and route --- crates/presentation/src/handlers.rs | 24 ++++++++++++++++++++++-- crates/presentation/src/routes.rs | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/presentation/src/handlers.rs b/crates/presentation/src/handlers.rs index c8b9e22..090f957 100644 --- a/crates/presentation/src/handlers.rs +++ b/crates/presentation/src/handlers.rs @@ -308,9 +308,9 @@ pub mod api { use uuid::Uuid; use application::{ - commands::{LoginCommand, LogReviewCommand, RegisterCommand, SyncPosterCommand}, + commands::{DeleteReviewCommand, LoginCommand, LogReviewCommand, RegisterCommand, SyncPosterCommand}, queries::{GetDiaryQuery, GetReviewHistoryQuery}, - use_cases::{get_diary, get_review_history, log_review, login as login_uc, register as register_uc, sync_poster}, + use_cases::{delete_review, get_diary, get_review_history, log_review, login as login_uc, register as register_uc, sync_poster}, }; use domain::{ errors::DomainError, @@ -469,6 +469,26 @@ pub mod api { Ok(StatusCode::CREATED) } + pub async fn delete_review( + State(state): State, + AuthenticatedUser(user_id): AuthenticatedUser, + Path(review_id): Path, + ) -> impl IntoResponse { + let cmd = DeleteReviewCommand { + review_id, + requesting_user_id: user_id.value(), + }; + match delete_review::execute(&state.app_ctx, cmd).await { + Ok(()) => StatusCode::NO_CONTENT.into_response(), + Err(DomainError::NotFound(_)) => StatusCode::NOT_FOUND.into_response(), + Err(DomainError::Unauthorized(_)) => StatusCode::FORBIDDEN.into_response(), + Err(e) => { + tracing::error!("delete_review error: {:?}", e); + StatusCode::INTERNAL_SERVER_ERROR.into_response() + } + } + } + fn movie_to_dto(movie: &Movie) -> MovieDto { MovieDto { id: movie.id().value(), diff --git a/crates/presentation/src/routes.rs b/crates/presentation/src/routes.rs index c1a2a81..5a5206c 100644 --- a/crates/presentation/src/routes.rs +++ b/crates/presentation/src/routes.rs @@ -42,6 +42,7 @@ fn api_routes() -> Router { routing::get(handlers::api::get_review_history), ) .route("/reviews", routing::post(handlers::api::post_review)) + .route("/reviews/{id}", routing::delete(handlers::api::delete_review)) .route( "/movies/{id}/sync-poster", routing::post(handlers::api::sync_poster),