Skip to content

Commit

Permalink
[BE] fix: 상품에 이미지가 있는 리뷰가 없을 경우 기본 이미지로 설정 (#822)
Browse files Browse the repository at this point in the history
* feat: 설정파일에 기본 이미지 경로 추가

* fix: 상품에 사진이 있는 리뷰가 하나도 없을 경우 기본 이미지 설정

* refactor: 설정파일에서 actuator 포트 옵션 제거
  • Loading branch information
hanueleee authored Oct 19, 2023
1 parent a51d2b7 commit 7575a5c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 11 deletions.
4 changes: 4 additions & 0 deletions backend/src/main/java/com/funeat/product/domain/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 17 additions & 2 deletions backend/src/main/java/com/funeat/product/domain/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -38,7 +41,11 @@ public class Product {
@OneToMany(mappedBy = "product")
private List<ProductRecipe> productRecipes;

private Long reviewCount = 0L;
@Value("${cloud.aws.image.food}")
private String basicFoodImage;

@Value("${cloud.aws.image.store}")
private String basicStoreImage;

protected Product() {
}
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ public void updateProductImage(final Long productId) {
final PageRequest pageRequest = PageRequest.of(FIRST_PAGE, ONE);

final List<Review> 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,
Expand Down
5 changes: 3 additions & 2 deletions backend/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ management:
enabled: true
prometheus:
enabled: true
server:
port: { SERVER_PORT }

cloud:
aws:
Expand All @@ -46,3 +44,6 @@ cloud:
bucket: { S3_BUCKET }
folder: { S3_DEV_FOLDER }
cloudfrontPath: { S3_DEV_CLOUDFRONT_PATH }
image:
food: { DEV_BASIC_FOOD_IMAGE }
store: { DEV_BASIC_STORE_IMAGE }
7 changes: 5 additions & 2 deletions backend/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ cloud:
static: { S3_REGION }
s3:
bucket: { S3_BUCKET }
folder: { S3_DEV_FOLDER }
cloudfrontPath: { S3_DEV_CLOUDFRONT_PATH }
folder: { S3_LOCAL_FOLDER }
cloudfrontPath: { S3_LOCAL_CLOUDFRONT_PATH }
image:
food: { LOCAL_BASIC_FOOD_IMAGE }
store: { LOCAL_BASIC_STORE_IMAGE }
5 changes: 3 additions & 2 deletions backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ management:
enabled: true
prometheus:
enabled: true
server:
port: { SERVER_PORT }

cloud:
aws:
Expand All @@ -45,3 +43,6 @@ cloud:
bucket: { S3_BUCKET }
folder: { S3_PROD_FOLDER }
cloudfrontPath: { S3_PROD_CLOUDFRONT_PATH }
image:
food: { PROD_BASIC_FOOD_IMAGE }
store: { PROD_BASIC_STORE_IMAGE }
3 changes: 3 additions & 0 deletions backend/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ cloud:
bucket: testBucket
folder: testFolder
cloudfrontPath: testCloudfrontPath
image:
food: foodimage
store: storeimage

back-office:
id: test
Expand Down

0 comments on commit 7575a5c

Please sign in to comment.