Skip to content

Commit

Permalink
fix: 존재하거나 존재하지 않을 때 분기처리 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
wugawuga committed Aug 3, 2023
1 parent 256db71 commit 6b982fe
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ReviewFavorite> 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,
Expand Down

0 comments on commit 6b982fe

Please sign in to comment.