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: 상품의 썸네일이었던 리뷰를 삭제했을 경우 썸네일이 업데이트 되지 않는 문제 해결 #815

Merged
merged 1 commit into from
Oct 19, 2023
Merged
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 @@ -247,19 +247,13 @@ public void deleteReview(final Long reviewId, final Long memberId) {

if (review.checkAuthor(member)) {
eventPublisher.publishEvent(new ReviewDeleteEvent(image));
updateProduct(product, review.getRating());
deleteThingsRelatedToReview(review);
updateProduct(product, review.getRating());
return;
}
throw new NotAuthorOfReviewException(NOT_AUTHOR_OF_REVIEW, memberId);
}

private void updateProduct(final Product product, final Long deletedRating) {
updateProductImage(product.getId());
product.updateAverageRatingForDelete(deletedRating);
product.minusReviewCount();
}

private void deleteThingsRelatedToReview(final Review review) {
deleteReviewTags(review);
deleteReviewFavorites(review);
Expand All @@ -282,6 +276,12 @@ private void deleteReviewFavorites(final Review review) {
reviewFavoriteRepository.deleteAllByIdInBatch(ids);
}

private void updateProduct(final Product product, final Long deletedRating) {
product.updateAverageRatingForDelete(deletedRating);
product.minusReviewCount();
updateProductImage(product.getId());
}

public Optional<MostFavoriteReviewResponse> getMostFavoriteReview(final Long productId) {
final Product findProduct = productRepository.findById(productId)
.orElseThrow(() -> new ProductNotFoundException(PRODUCT_NOT_FOUND, productId));
Expand Down