diff --git a/backend/src/main/java/com/funeat/product/domain/Product.java b/backend/src/main/java/com/funeat/product/domain/Product.java index e66aa59cf..a8f7cf07d 100644 --- a/backend/src/main/java/com/funeat/product/domain/Product.java +++ b/backend/src/main/java/com/funeat/product/domain/Product.java @@ -3,6 +3,8 @@ import com.funeat.member.domain.bookmark.ProductBookmark; import com.funeat.review.domain.Review; import java.util.List; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicLong; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; @@ -42,6 +44,8 @@ public class Product { @OneToMany(mappedBy = "product") private List productBookmarks; + private AtomicLong reviewCount = new AtomicLong(0); + protected Product() { } @@ -106,4 +110,12 @@ public Double getAverageRating() { public Category getCategory() { return category; } + + public Long getReviewCount() { + return reviewCount.get(); + } + + public void addReviewCount() { + reviewCount.incrementAndGet(); + } } diff --git a/backend/src/main/java/com/funeat/review/application/ReviewService.java b/backend/src/main/java/com/funeat/review/application/ReviewService.java index 2cf840ed1..ec7020cad 100644 --- a/backend/src/main/java/com/funeat/review/application/ReviewService.java +++ b/backend/src/main/java/com/funeat/review/application/ReviewService.java @@ -95,6 +95,7 @@ public void create(final Long productId, final Long memberId, final MultipartFil final Long countByProduct = reviewRepository.countByProduct(findProduct); findProduct.updateAverageRating(savedReview.getRating(), countByProduct); + findProduct.addReviewCount(); reviewTagRepository.saveAll(reviewTags); }