Skip to content

Commit

Permalink
fix: 리뷰 삭제시 썸네일 업데이트 로직 순서 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hanueleee committed Oct 19, 2023
1 parent 800f563 commit 8627b8a
Showing 1 changed file with 7 additions and 7 deletions.
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

0 comments on commit 8627b8a

Please sign in to comment.