Skip to content

Commit

Permalink
[BE] fix: 리뷰 좋아요가 존재하거나 존재하지 않을 때 분기처리 수정 (#276)
Browse files Browse the repository at this point in the history
* fix: 존재하거나 존재하지 않을 때 분기처리 수정

* refactor: 분기처리 orElseGet 으로 수정
  • Loading branch information
wugawuga authored Aug 3, 2023
1 parent 256db71 commit 29fc39b
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 29fc39b

Please sign in to comment.