From 6baab7d0e9bb936997797706fcdfe981647c7501 Mon Sep 17 00:00:00 2001 From: hanueleee Date: Thu, 19 Oct 2023 19:28:19 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=83=81=ED=92=88=EC=97=90=20=EC=82=AC?= =?UTF-8?q?=EC=A7=84=EC=9D=B4=20=EC=9E=88=EB=8A=94=20=EB=A6=AC=EB=B7=B0?= =?UTF-8?q?=EA=B0=80=20=ED=95=98=EB=82=98=EB=8F=84=20=EC=97=86=EC=9D=84=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EA=B8=B0=EB=B3=B8=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/funeat/product/domain/Category.java | 4 ++++ .../com/funeat/product/domain/Product.java | 19 +++++++++++++++++-- .../review/application/ReviewService.java | 8 +++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/funeat/product/domain/Category.java b/backend/src/main/java/com/funeat/product/domain/Category.java index 7702a087e..7504aad1d 100644 --- a/backend/src/main/java/com/funeat/product/domain/Category.java +++ b/backend/src/main/java/com/funeat/product/domain/Category.java @@ -30,6 +30,10 @@ public Category(final String name, final CategoryType type, final String image) this.image = image; } + public boolean isFood() { + return type == CategoryType.FOOD; + } + public Long getId() { return id; } 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 d5c3607c1..818217d34 100644 --- a/backend/src/main/java/com/funeat/product/domain/Product.java +++ b/backend/src/main/java/com/funeat/product/domain/Product.java @@ -10,6 +10,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import org.springframework.beans.factory.annotation.Value; @Entity public class Product { @@ -28,6 +29,8 @@ public class Product { private Double averageRating = 0.0; + private Long reviewCount = 0L; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "category_id") private Category category; @@ -38,7 +41,11 @@ public class Product { @OneToMany(mappedBy = "product") private List productRecipes; - private Long reviewCount = 0L; + @Value("${cloud.aws.image.food}") + private String basicFoodImage; + + @Value("${cloud.aws.image.store}") + private String basicStoreImage; protected Product() { } @@ -107,7 +114,15 @@ public Double calculateRankingScore(final Long reviewCount) { return averageRating - (averageRating - 3.0) * factor; } - public void updateImage(final String topFavoriteImage) { + public void updateBasicImage() { + if (category.isFood()) { + this.image = basicFoodImage; + return; + } + this.image = basicStoreImage; + } + + public void updateFavoriteImage(final String topFavoriteImage) { this.image = topFavoriteImage; } 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 f492e90bb..a65922c82 100644 --- a/backend/src/main/java/com/funeat/review/application/ReviewService.java +++ b/backend/src/main/java/com/funeat/review/application/ReviewService.java @@ -146,10 +146,12 @@ public void updateProductImage(final Long productId) { final PageRequest pageRequest = PageRequest.of(FIRST_PAGE, ONE); final List topFavoriteReview = reviewRepository.findPopularReviewWithImage(productId, pageRequest); - if (!topFavoriteReview.isEmpty()) { - final String topFavoriteReviewImage = topFavoriteReview.get(START_INDEX).getImage(); - product.updateImage(topFavoriteReviewImage); + if (topFavoriteReview.isEmpty()) { + product.updateBasicImage(); + return; } + final String topFavoriteReviewImage = topFavoriteReview.get(START_INDEX).getImage(); + product.updateFavoriteImage(topFavoriteReviewImage); } public SortingReviewsResponse sortingReviews(final Long productId, final Long memberId,