Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ out/
/eat-ssu.tar

### env file ###
.env
.env

/src/main/resources/application-local.yml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

.gitignoreapplication-local.yml 파일을 추가하여 버전 관리에서 제외하도록 설정하셨지만, 이번 PR에서 해당 파일의 변경사항이 커밋에 포함되었습니다. 이로 인해 .gitignore 설정이 의도한 대로 동작하지 않고 민감한 정보가 노출될 수 있습니다. application-local.yml 파일의 변경 사항을 커밋에서 제외하고, Git 추적에서 제거해야 합니다. git rm --cached src/main/resources/application-local.yml 명령어를 사용하여 추적을 중단할 수 있습니다.

Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,6 @@ public Double getMainRatingAverage(Long mealId) {
.fetchOne();
}

public Double getTasteRatingAverage(Long mealId) {
List<Long> menuIds = mealMenuQueryRepository.getMenuIds(mealId);
return queryFactory
.select(review.ratings.tasteRating.avg())
.from(review)
.join(review.menu, menu)
.where(
menuIdIn(menuIds)
)
.fetchOne();
}

public Double getAmountRatingAverage(Long mealId) {
List<Long> menuIds = mealMenuQueryRepository.getMenuIds(mealId);
return queryFactory
.select(review.ratings.amountRating.avg())
.from(review)
.join(review.menu, menu)
.where(
menuIdIn(menuIds)
)
.fetchOne();
}

private BooleanExpression menuIdIn(List<Long> menuIds) {
return menuIds != null && !menuIds.isEmpty() ? menu.id.in(menuIds) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,7 @@ public Double getMainRatingAverage(Long menuId) {
.fetchOne();
}

public Double getTasteRatingAverage(Long menuId) {
return queryFactory
.select(review.ratings.tasteRating.avg())
.from(review)
.join(review.menu, menu)
.where(
menuIdEq(menuId)
)
.fetchOne();
}

public Double getAmountRatingAverage(Long menuId) {
return queryFactory
.select(review.ratings.amountRating.avg())
.from(review)
.join(review.menu, menu)
.where(
menuIdEq(menuId)
)
.fetchOne();
}

private BooleanExpression menuIdEq(Long menuId) {
return menu.id.eq(menuId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public enum RestaurantType {
RESTAURANT("음식점"),
CAFE("카페"),
BEER("주점");
PUB("주점");

private final String type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ public RatingAverages mealAverageRatings(Meal meal) {
long totalReviewCount = mealTotalReviewCount(meal);

if (totalReviewCount == 0)
return new RatingAverages(null, null, null);
return new RatingAverages(null);

return RatingAverages.builder()
.mainRating(averageRating(mealTotalMainRating(meal), totalReviewCount))
.amountRating(averageRating(mealTotalAmountRating(meal), totalReviewCount))
.tasteRating(averageRating(mealTotalTasteRating(meal), totalReviewCount))
.build();
}

Expand All @@ -48,13 +46,11 @@ public RatingAverages menuAverageRatings(Menu menu) {
int totalReviewCount = menu.getTotalReviewCount();

if (totalReviewCount == 0) {
return new RatingAverages(null, null, null);
return new RatingAverages(null);
}

return RatingAverages.builder()
.mainRating(averageRating(menuTotalMainRating(menu), totalReviewCount))
.amountRating(averageRating(menuTotalAmountRating(menu), totalReviewCount))
.tasteRating(averageRating(menuTotalTasteRating(menu), totalReviewCount))
.build();
}

Expand Down Expand Up @@ -101,35 +97,11 @@ public Integer mealTotalMainRating(Meal meal) {
.reduce(null, this::sum);
}

// 식단 양 평점 총합
public Integer mealTotalAmountRating(Meal meal) {
return meal.getMealMenus().stream()
.map(MealMenu::getMenu)
.map(menu -> menu.getReviews().getTotalAmountRating())
.reduce(null, this::sum);
}

// 식단 맛 평점 총합
public Integer mealTotalTasteRating(Meal meal) {
return meal.getMealMenus().stream()
.map(MealMenu::getMenu)
.map(menu -> menu.getReviews().getTotalTasteRating())
.reduce(null, this::sum);
}

// 메뉴 메인 평점 총합
public Integer menuTotalMainRating(Menu menu) {
return menu.getReviews().getTotalMainRating();
}

// 메뉴 양 평점 총합
public Integer menuTotalAmountRating(Menu menu) {
return menu.getReviews().getTotalAmountRating();
}

// 메뉴 맛 평점 총합
public Integer menuTotalTasteRating(Menu menu) {
return menu.getReviews().getTotalTasteRating();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,14 @@ public RatingAverages mealAverageRatings(Meal meal) {
long totalReviewCount = mealTotalReviewCount(meal);

if (totalReviewCount == 0)
return new RatingAverages(null, null, null);
return new RatingAverages(null);

Collection<RatingsDto> mealRatings = reviewRepository.findByMenu_MealMenus_Meal(meal, RatingsDto.class);

Integer totalMainRating = mealRatings.stream().mapToInt(RatingsDto::getMainRating).sum();
Integer totalTasteRating = mealRatings.stream().mapToInt(RatingsDto::getTasteRating).sum();
Integer totalAmountRating = mealRatings.stream().mapToInt(RatingsDto::getAmountRating).sum();

return RatingAverages.builder()
.mainRating(averageRating(totalMainRating, totalReviewCount))
.tasteRating(averageRating(totalTasteRating, totalReviewCount))
.amountRating(averageRating(totalAmountRating, totalReviewCount))
.build();
}

Expand Down
14 changes: 3 additions & 11 deletions src/main/java/ssu/eatssu/domain/rating/entity/Ratings.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,12 @@ public class Ratings {

private Integer mainRating;

private Integer amountRating;

private Integer tasteRating;

private Ratings(Integer mainRating, Integer amountRating, Integer tasteRating) {
private Ratings(Integer mainRating) {
Assert.isTrue(mainRating >= 0 && mainRating <= 5, "mainRating must be between 0 and 5");
Assert.isTrue(amountRating >= 0 && amountRating <= 5, "amountRating must be between 0 and 5");
Assert.isTrue(tasteRating >= 0 && tasteRating <= 5, "tasteRating must be between 0 and 5");
this.mainRating = mainRating;
this.amountRating = amountRating;
this.tasteRating = tasteRating;
}

public static Ratings of(Integer mainRating, Integer amountRating, Integer tasteRating) {
return new Ratings(mainRating, amountRating, tasteRating);
public static Ratings of(Integer mainRating) {
return new Ratings(mainRating);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ public class CreateMenuReviewRequest {
private Long menuId;
@Schema(description = "평점-메인", example = "4")
private Integer mainRating;

@Schema(description = "평점-양", example = "4")
private Integer amountRating;

@Schema(description = "평점-맛", example = "4")
private Integer tasteRating;

@Max(150)
@Schema(description = "한줄평", example = "맛있어용")
private String content;
Expand All @@ -36,19 +29,8 @@ public class CreateMenuReviewRequest {
private String imageUrl;
private MenuLikeRequest menuLike;

public CreateMenuReviewRequest(int mainRating, int amountRating, int tasteRating, String content) {
Assert.isTrue(mainRating >= 1 && mainRating <= 5, "평점은 1에서 5 사이 여야 합니다.");
Assert.isTrue(amountRating >= 1 && amountRating <= 5, "평점은 1에서 5 사이 여야 합니다.");
Assert.isTrue(tasteRating >= 1 && tasteRating <= 5, "평점은 1에서 5 사이 여야 합니다.");
Assert.notNull(content, "리뷰는 null이 될 수 없습니다.");
this.mainRating = mainRating;
this.amountRating = amountRating;
this.tasteRating = tasteRating;
this.content = content;
}

public Review toReviewEntity(User user, Menu menu) {
Ratings ratings = Ratings.of(this.mainRating, this.amountRating, this.tasteRating);
Ratings ratings = Ratings.of(this.mainRating);
return Review.builder()
.user(user)
.content(this.content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public static MealReviewsResponse of(Long totalReviewCount, List<String> menuNam
return MealReviewsResponse.builder()
.menuNames(menuNames)
.mainRating(ratingAverages.mainRating())
.amountRating(ratingAverages.amountRating())
.tasteRating(ratingAverages.tasteRating())
.totalReviewCount(totalReviewCount)
.reviewRatingCount(reviewRatingCount)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
public class MenuLikeRequest {
@Schema(description = "메뉴 식별자", example = "123")
private Long menuId;
@Schema(description = "좋아요 or 싫어요", example = "좋아요 : true or 싫어요 : false")
@Schema(description = "좋아요 선택", example = "좋아요 : true (기본값은 false)")
private Boolean isLike;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public static MenuReviewResponse of(Menu menu,
.menuName(menu.getName())
.totalReviewCount(menu.getTotalReviewCount())
.mainRating(ratingAverages.mainRating())
.amountRating(ratingAverages.amountRating())
.tasteRating(ratingAverages.tasteRating())
.reviewRatingCount(reviewRatingCount)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.Builder;

public record RatingAverages(Double mainRating, Double amountRating, Double tasteRating) {
public record RatingAverages(Double mainRating) {

@Builder
public RatingAverages {
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/ssu/eatssu/domain/review/dto/RatingsDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,5 @@ public Integer getMainRating() {
return ratings.getMainRating();
}

public Integer getTasteRating() {
return ratings.getTasteRating();
}

public Integer getAmountRating() {
return ratings.getAmountRating();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@ public class ReviewCreateRequest {
@Schema(description = "한줄평", example = "맛있어용")
private String content;

public ReviewCreateRequest(int mainRating, int amountRating, int tasteRating, String content) {
public ReviewCreateRequest(int mainRating, String content) {
Assert.isTrue(mainRating >= 1 && mainRating <= 5, "평점은 1에서 5 사이 여야 합니다.");
Assert.isTrue(amountRating >= 1 && amountRating <= 5, "평점은 1에서 5 사이 여야 합니다.");
Assert.isTrue(tasteRating >= 1 && tasteRating <= 5, "평점은 1에서 5 사이 여야 합니다.");
Assert.notNull(content, "리뷰는 null이 될 수 없습니다.");
this.mainRating = mainRating;
this.amountRating = amountRating;
this.tasteRating = tasteRating;
this.content = content;
}

public Review toEntity(User user, Menu menu) {
Ratings ratings = Ratings.of(this.mainRating, this.amountRating, this.tasteRating);
Ratings ratings = Ratings.of(this.mainRating);
return Review.builder()
.user(user)
.content(this.content)
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/ssu/eatssu/domain/review/dto/ReviewDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public static ReviewDetail from(Review review, Long userId) {
ReviewDetailBuilder builder = ReviewDetail.builder()
.reviewId(review.getId())
.mainRating(review.getRatings().getMainRating())
.amountRating(review.getRatings().getAmountRating())
.tasteRating(review.getRatings().getTasteRating())
.writedAt(review.getCreatedDate().toLocalDate())
.content(review.getContent())
.imageUrls(imageUrls)
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/ssu/eatssu/domain/review/dto/ReviewRatingCount.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import ssu.eatssu.domain.review.entity.Review;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

//COMMENT: 더 좋은 매개변수 명이 있을 것 같은데 제 머리로는 이게 한계입니다... 멋진 변수명으로 바꿔주세요
Expand All @@ -15,18 +15,22 @@ public record ReviewRatingCount(long oneStarCount, long twoStarCount, long three
}

public static ReviewRatingCount from(List<Review> reviews) {
Map<Integer, Long> ratingDistribution = reviews.stream()
.filter(r -> r.getRating() != null)
.collect(Collectors.groupingBy(Review::getRating,
LinkedHashMap::new,
Collectors.counting()));
Map<Integer, Long> countsByStar = reviews.stream()
.map(r -> {
Integer main = (r.getRatings() != null) ? r.getRatings()
.getMainRating() : null;
return (main != null) ? main : r.getRating();
})
.filter(Objects::nonNull)
.collect(Collectors.groupingBy(Integer::intValue,
Collectors.counting()));

return new ReviewRatingCount(
ratingDistribution.getOrDefault(1, 0L),
ratingDistribution.getOrDefault(2, 0L),
ratingDistribution.getOrDefault(3, 0L),
ratingDistribution.getOrDefault(4, 0L),
ratingDistribution.getOrDefault(5, 0L)
countsByStar.getOrDefault(1, 0L),
countsByStar.getOrDefault(2, 0L),
countsByStar.getOrDefault(3, 0L),
countsByStar.getOrDefault(4, 0L),
countsByStar.getOrDefault(5, 0L)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,22 @@ public class UploadReviewRequest {
@Schema(description = "평점-메인", example = "4")
private Integer mainRating;

@Schema(description = "평점-양", example = "4")
private Integer amountRating;

@Schema(description = "평점-맛", example = "4")
private Integer tasteRating;

@Max(150)
@Schema(description = "한줄평", example = "맛있어용")
private String content;

@Schema(description = "리뷰 이미지 URL", example = "https://s3.~~~.jpg")
private String imageUrl;

public UploadReviewRequest(int mainRating, int amountRating, int tasteRating, String content) {
public UploadReviewRequest(int mainRating, String content) {
Assert.isTrue(mainRating >= 1 && mainRating <= 5, "평점은 1에서 5 사이 여야 합니다.");
Assert.isTrue(amountRating >= 1 && amountRating <= 5, "평점은 1에서 5 사이 여야 합니다.");
Assert.isTrue(tasteRating >= 1 && tasteRating <= 5, "평점은 1에서 5 사이 여야 합니다.");
Assert.notNull(content, "리뷰는 null이 될 수 없습니다.");
this.mainRating = mainRating;
this.amountRating = amountRating;
this.tasteRating = tasteRating;
this.content = content;
}

public Review toReviewEntity(User user, Menu menu) {
Ratings ratings = Ratings.of(this.mainRating, this.amountRating, this.tasteRating);
Ratings ratings = Ratings.of(this.mainRating);
return Review.builder()
.user(user)
.content(this.content)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ssu/eatssu/domain/review/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public class Review extends BaseTimeEntity {
@OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ReviewLike> reviewLikes = new ArrayList<>();

public void update(String content, Integer mainRate, Integer amountRate, Integer tasteRate) {
public void update(String content, Integer mainRate) {
this.content = content;
this.ratings = Ratings.of(mainRate, amountRate, tasteRate);
this.ratings = Ratings.of(mainRate);
}

// TODO : this.user가 null이면?
Expand Down
Loading