feat(presentation): add DELETE /api/reviews/:id handler and route

This commit is contained in:
2026-05-04 14:24:48 +02:00
parent f94d2db8b1
commit 5baff54cb9
2 changed files with 23 additions and 2 deletions

View File

@@ -308,9 +308,9 @@ pub mod api {
use uuid::Uuid; use uuid::Uuid;
use application::{ use application::{
commands::{LoginCommand, LogReviewCommand, RegisterCommand, SyncPosterCommand}, commands::{DeleteReviewCommand, LoginCommand, LogReviewCommand, RegisterCommand, SyncPosterCommand},
queries::{GetDiaryQuery, GetReviewHistoryQuery}, 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::{ use domain::{
errors::DomainError, errors::DomainError,
@@ -469,6 +469,26 @@ pub mod api {
Ok(StatusCode::CREATED) Ok(StatusCode::CREATED)
} }
pub async fn delete_review(
State(state): State<AppState>,
AuthenticatedUser(user_id): AuthenticatedUser,
Path(review_id): Path<Uuid>,
) -> 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 { fn movie_to_dto(movie: &Movie) -> MovieDto {
MovieDto { MovieDto {
id: movie.id().value(), id: movie.id().value(),

View File

@@ -42,6 +42,7 @@ fn api_routes() -> Router<AppState> {
routing::get(handlers::api::get_review_history), routing::get(handlers::api::get_review_history),
) )
.route("/reviews", routing::post(handlers::api::post_review)) .route("/reviews", routing::post(handlers::api::post_review))
.route("/reviews/{id}", routing::delete(handlers::api::delete_review))
.route( .route(
"/movies/{id}/sync-poster", "/movies/{id}/sync-poster",
routing::post(handlers::api::sync_poster), routing::post(handlers::api::sync_poster),