diff --git a/backend/src/main/java/com/funeat/review/application/ReviewService.java b/backend/src/main/java/com/funeat/review/application/ReviewService.java index 910e48144..aad5de8b5 100644 --- a/backend/src/main/java/com/funeat/review/application/ReviewService.java +++ b/backend/src/main/java/com/funeat/review/application/ReviewService.java @@ -93,13 +93,17 @@ public void likeReview(final Long reviewId, final Long memberId, final ReviewFav final Review findReview = reviewRepository.findById(reviewId) .orElseThrow(IllegalArgumentException::new); - final ReviewFavorite reviewFavorite = ReviewFavorite.createReviewFavoriteByMemberAndReview(findMember, - findReview, request.getFavorite()); + final ReviewFavorite savedReviewFavorite = reviewFavoriteRepository.findByMemberAndReview(findMember, + findReview).orElseGet(() -> saveReviewFavorite(findMember, findReview, request.getFavorite())); - final ReviewFavorite findReviewFavorite = reviewFavoriteRepository.findByMemberAndReview(findMember, findReview) - .orElse(reviewFavoriteRepository.save(reviewFavorite)); + savedReviewFavorite.updateChecked(request.getFavorite()); + } + + private ReviewFavorite saveReviewFavorite(final Member member, final Review review, final Boolean favorite) { + final ReviewFavorite reviewFavorite = ReviewFavorite.createReviewFavoriteByMemberAndReview(member, review, + favorite); - findReviewFavorite.updateChecked(request.getFavorite()); + return reviewFavoriteRepository.save(reviewFavorite); } public SortingReviewsResponse sortingReviews(final Long productId,