Skip to content

Commit

Permalink
fix: review save usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Aug 3, 2024
1 parent eb721f8 commit 49193c1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void saveReviewLike(Long reviewId, String accessToken) {
User user = userQueryService.findByEmail(email);
Review review = reviewQueryService.findReviewById(reviewId);

if (reviewQueryService.countReviewLike(reviewId) > 0) {
if (reviewQueryService.countReviewLikeAndUserId(reviewId, user.getUserId()) > 0) {
throw new ReviewException(ReviewErrorCode.EXIST_REVIEW_LIKE);
} else {
final ReviewLike reviewLike = ReviewLike.builder().user(user).review(review).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface ReviewLikeRepository extends JpaRepository<ReviewLike, Long> {

Integer countAllByUserUserIdAndReviewId(Long userId, Long reviewId);

Integer countAllByReviewId(Long reviewId);
Integer countAllByReviewIdAndUserUserId(Long reviewId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void saveReviewLike(ReviewLike reviewLike) {
reviewLikeRepository.save(reviewLike);
}

public Integer countReviewLike(Long reviewId) {
return reviewLikeRepository.countAllByReviewId(reviewId);
public Integer countReviewLikeAndUserId(Long reviewId, Long userId) {
return reviewLikeRepository.countAllByReviewIdAndUserUserId(reviewId, userId);
}

public void deleteReview(Long id) {
Expand Down

0 comments on commit 49193c1

Please sign in to comment.