Review Delete Controller
In this lesson, we'll add the delete functionality to our ReviewController, enabling users to remove their reviews from restaurants through our REST API.
Implementing the Delete Endpoint
The delete endpoint follows REST conventions by using the HTTP DELETE method to remove a specific review.
Let's implement the deleteReview method in our ReviewController:
@DeleteMapping("/{reviewId}")
public ResponseEntity<Void> deleteReview(
@PathVariable String restaurantId,
@PathVariable String reviewId
) {
reviewService.deleteReview(restaurantId, reviewId);
return ResponseEntity.noContent().build();
}Summary
- Added
deleteReviewendpoint using@DeleteMappingannotation - Method accepts
restaurantIdandreviewIdas path variables - Returns HTTP 204 status code on successful deletion