Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] fix: 리뷰 좋아요가 존재하거나 존재하지 않을 때 분기처리 수정 #276

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
wugawuga marked this conversation as resolved.
Show resolved Hide resolved

public SortingReviewsResponse sortingReviews(final Long productId,
Expand Down
Loading