Skip to content

Commit

Permalink
[BE] Product 엔티티에 reviewCount 필드 추가 (#616)
Browse files Browse the repository at this point in the history
* feat: Product 엔티티의 필드에 reviewCount 추가

* feat: Review 작성시 product의 reviewCount 1증가 기능 구현

* refactor: Product의 ReviewCount 필드의 자료형을 AtomicLong으로 수정

* refactor: AtomicLong 관련 set 제거
  • Loading branch information
hanueleee authored Sep 17, 2023
1 parent 14558cb commit cc2266c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/src/main/java/com/funeat/product/domain/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,6 +44,8 @@ public class Product {
@OneToMany(mappedBy = "product")
private List<ProductBookmark> productBookmarks;

private AtomicLong reviewCount = new AtomicLong(0);

protected Product() {
}

Expand Down Expand Up @@ -106,4 +110,12 @@ public Double getAverageRating() {
public Category getCategory() {
return category;
}

public Long getReviewCount() {
return reviewCount.get();
}

public void addReviewCount() {
reviewCount.incrementAndGet();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit cc2266c

Please sign in to comment.