Skip to content

Commit

Permalink
Merge pull request #12 from 9oormthon-univ/feature/#11
Browse files Browse the repository at this point in the history
[FEAT] 기업 리뷰 삭제 API 구현
  • Loading branch information
haeun1107 authored Nov 18, 2024
2 parents 9b640cd + 688240f commit 1fab671
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ public ApiResponse<PostReviewResponse> updateReview(
PostReviewResponse response = reviewService.updateReview(reviewId, postReviewRequest, authentication.getName());
return ApiResponse.onSuccess(response);
}

@DeleteMapping("/{reviewId}")
@Operation(summary = "리뷰 삭제 API", description = "사용자가 작성한 리뷰를 삭제합니다.")
public ApiResponse<String> deleteReview(@PathVariable Long reviewId, Authentication authentication) {
reviewService.deleteReview(reviewId, authentication.getName());
return ApiResponse.onSuccess(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public interface ReviewService {
public PostReviewResponse createReview(PostReviewRequest postReviewRequest, String userId);
public MyReviewsWrapperResponse getMyReviews(String userId);
public PostReviewResponse updateReview(Long reviewId, PostReviewRequest postReviewRequest, String userId);
String deleteReview(Long reviewId, String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,22 @@ public PostReviewResponse updateReview(Long reviewId, PostReviewRequest postRevi

return ReviewConverter.toReviewResponse(review);
}

@Transactional
public String deleteReview(Long reviewId, String userId) {
User user = userRepository.findById(Long.valueOf(userId))
.orElseThrow(() -> new RuntimeException("존재하지 않는 사용자입니다."));

Review review = reviewRepository.findById(reviewId)
.orElseThrow(() -> new RuntimeException("존재하지 않는 리뷰입니다."));

if (!review.getUser().getUserId().equals(user.getUserId())) {
throw new RuntimeException("사용자가 작성한 리뷰가 아닙니다.");
}

// 리뷰 삭제
tagListRepository.deleteAll(tagListRepository.findByReview(review)); // 관련 태그 삭제
reviewRepository.delete(review); // 리뷰 삭제
return "성공!";
}
}

0 comments on commit 1fab671

Please sign in to comment.