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

[BSVR-260] 리뷰 수정 isLiked, isScrapped 버그 해결 #188

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -318,20 +318,4 @@ public Review mapKeywordsToReview(Review review) {

return mappedReview;
}

private void setLikedAndScrappedStatus(List<Review> reviews, Long memberId) {
List<Long> reviewIds = reviews.stream().map(Review::getId).collect(Collectors.toList());

Map<Long, Boolean> likedMap =
reviewLikeRepository.existsByMemberIdAndReviewIds(memberId, reviewIds);
Map<Long, Boolean> scrappedMap =
reviewScrapRepository.existsByMemberIdAndReviewIds(memberId, reviewIds);

reviews.forEach(
review -> {
boolean isLiked = likedMap.getOrDefault(review.getId(), false);
boolean isScrapped = scrappedMap.getOrDefault(review.getId(), false);
review.setLikedAndScrapped(isLiked, isScrapped);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.depromeet.spot.domain.review.keyword.Keyword;
import org.depromeet.spot.usecase.port.in.review.UpdateReviewUsecase;
import org.depromeet.spot.usecase.port.out.review.ReviewRepository;
import org.depromeet.spot.usecase.service.review.processor.ReadReviewProcessor;
import org.depromeet.spot.usecase.service.review.processor.ReviewCreationProcessor;
import org.depromeet.spot.usecase.service.review.processor.ReviewDataProcessor;
import org.depromeet.spot.usecase.service.review.processor.ReviewKeywordProcessor;
Expand All @@ -28,6 +29,7 @@ public class UpdateReviewService implements UpdateReviewUsecase {
private final ReviewDataProcessor reviewDataProcessor;
private final ReviewKeywordProcessor reviewKeywordProcessor;
private final ReviewCreationProcessor reviewCreationProcessor;
private final ReadReviewProcessor readReviewProcessor;

public UpdateReviewResult updateReview(
Long memberId, Long reviewId, UpdateReviewCommand command) {
Expand All @@ -49,6 +51,9 @@ public UpdateReviewResult updateReview(
reviewKeywordProcessor.updateBlockTopKeywords(existingReview, savedReview);
savedReview.setKeywordMap(keywordMap);

// 유저의 리뷰 좋아요, 스크랩 여부
readReviewProcessor.setLikedAndScrappedStatus(savedReview, memberId);

return new UpdateReviewResult(savedReview);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
public interface ReadReviewProcessor {

void setLikedAndScrappedStatus(List<Review> reviews, Long memberId);

void setLikedAndScrappedStatus(Review review, Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ public void setLikedAndScrappedStatus(List<Review> reviews, Long memberId) {
review.setLikedAndScrapped(isLiked, isScrapped);
});
}

@Override
public void setLikedAndScrappedStatus(Review review, Long memberId) {
boolean isLiked = reviewLikeRepository.existsBy(memberId, review.getId());
boolean isScrapped = reviewScrapRepository.existsBy(memberId, review.getId());
review.setLikedAndScrapped(isLiked, isScrapped);
}
}
Loading