Skip to content

Commit

Permalink
feat: 리뷰 삭제 API 추가 #113
Browse files Browse the repository at this point in the history
  • Loading branch information
feel-coding committed Jan 11, 2024
1 parent 82e4371 commit 9e7ec5a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/cvsgo/controller/ReviewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public SuccessResponse<Void> updateReview(@LoginUser User user, @PathVariable Lo
return SuccessResponse.create();
}

@DeleteMapping("/reviews/{reviewId}")
public SuccessResponse<Void> deleteReview(@LoginUser User user, @PathVariable Long reviewId) {
reviewService.deleteReview(user, reviewId);
return SuccessResponse.create();
}

@PostMapping("/reviews/{reviewId}/likes")
@ResponseStatus(HttpStatus.CREATED)
public SuccessResponse<Void> createReviewLike(@LoginUser User user,
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/cvsgo/service/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ public void updateReview(User user, Long reviewId, UpdateReviewRequestDto reques
review.updateRating(request.getRating());
}

/**
* 리뷰를 삭제합니다.
*
* @param user 현재 로그인한 사용자
* @param reviewId 삭제하려는 리뷰 ID
*/
@Transactional
public void deleteReview(User user, Long reviewId) {
Review review = reviewRepository.findById(reviewId).orElseThrow(() -> NOT_FOUND_REVIEW);
if (!review.getUser().equals(user)) {
throw FORBIDDEN_REVIEW;
}
reviewRepository.delete(review);
}

/**
* 필터를 적용하여 리뷰를 조회합니다.
*
Expand Down

0 comments on commit 9e7ec5a

Please sign in to comment.