From 6b982fe4551ffd80023ea80101b53c653a11d7ab Mon Sep 17 00:00:00 2001 From: wugawuga Date: Thu, 3 Aug 2023 10:21:59 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A1=B4=EC=9E=AC=ED=95=98=EA=B1=B0?= =?UTF-8?q?=EB=82=98=20=EC=A1=B4=EC=9E=AC=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20=EB=B6=84=EA=B8=B0=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funeat/review/application/ReviewService.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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..bbd9c0611 100644 --- a/backend/src/main/java/com/funeat/review/application/ReviewService.java +++ b/backend/src/main/java/com/funeat/review/application/ReviewService.java @@ -21,6 +21,7 @@ import com.funeat.tag.persistence.TagRepository; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -93,13 +94,18 @@ 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 Optional findReviewFavorite = reviewFavoriteRepository.findByMemberAndReview(findMember, + findReview); - final ReviewFavorite findReviewFavorite = reviewFavoriteRepository.findByMemberAndReview(findMember, findReview) - .orElse(reviewFavoriteRepository.save(reviewFavorite)); + if (findReviewFavorite.isPresent()) { + findReviewFavorite.get().updateChecked(request.getFavorite()); + return; + } - findReviewFavorite.updateChecked(request.getFavorite()); + final ReviewFavorite newReviewFavorite = ReviewFavorite.createReviewFavoriteByMemberAndReview(findMember, + findReview, request.getFavorite()); + final ReviewFavorite savedReviewFavorite = reviewFavoriteRepository.save(newReviewFavorite); + savedReviewFavorite.updateChecked(request.getFavorite()); } public SortingReviewsResponse sortingReviews(final Long productId,