Skip to content

Commit

Permalink
Merge pull request #75 from 28th-meetup/fix/typeChange
Browse files Browse the repository at this point in the history
feat: 가게 평점 double 타입으로 변경
  • Loading branch information
summit45 authored Nov 22, 2023
2 parents 9f430a9 + f915793 commit 9e6c70a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
29 changes: 14 additions & 15 deletions src/main/java/com/kusitms/jipbap/food/FoodService.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class FoodService {
private final StoreRepository storeRepository;
private final FoodRepository foodRepository;
private final CategoryRepository categoryRepository;
private final OrderRepository orderRepository;
private final FoodOptionRepository foodOptionRepository;
private final OrderDetailRepository orderDetailRepository;

Expand Down Expand Up @@ -142,7 +141,7 @@ public FoodDetailResponse getFoodDetail(Long foodId) {
.foodPackage(food.getFoodPackage())
.informationDescription(food.getInformationDescription())
.ingredient(food.getIngredient())
.minOrderAmount(food.getStore().getMinOrderAmount())
.minOrderAmount(roundToTwoDecimals(food.getStore().getMinOrderAmount()))
.foodOptionResponseList(foodOptionResponseList)
.build();
}
Expand Down Expand Up @@ -180,17 +179,17 @@ private List<FoodPreviewResponse> getBestSellingFoodByRegion(Long globalRegionId
.collect(Collectors.toList());

List<FoodPreviewResponse> bestSellingFoodResponseList = top10FoodList.stream()
.map(food -> new FoodPreviewResponse (
food.getId(),
food.getName(),
food.getStore().getId(),
food.getStore().getName(),
roundToTwoDecimals(food.getDollarPrice()),
roundToTwoDecimals(food.getCanadaPrice()),
food.getImage(),
food.getStore().getAvgRate()
))
.collect(Collectors.toList());
.map(food -> new FoodPreviewResponse (
food.getId(),
food.getName(),
food.getStore().getId(),
food.getStore().getName(),
roundToTwoDecimals(food.getDollarPrice()),
roundToTwoDecimals(food.getCanadaPrice()),
food.getImage(),
roundToTwoDecimals(food.getStore().getAvgRate())
))
.collect(Collectors.toList());

return bestSellingFoodResponseList;
}
Expand All @@ -214,7 +213,7 @@ private List<FoodPreviewResponse> getLatestSellingFoodByRegion(Long globalRegion
roundToTwoDecimals(food.getDollarPrice()),
roundToTwoDecimals(food.getCanadaPrice()),
food.getImage(),
food.getStore().getAvgRate()
roundToTwoDecimals(food.getStore().getAvgRate())
))
.collect(Collectors.toList());
return latestSellingFoodResponseList;
Expand Down Expand Up @@ -242,7 +241,7 @@ public List<FoodPreviewResponse> getFoodByCategory(AuthInfo authInfo, Long categ
roundToTwoDecimals(food.getDollarPrice()),
roundToTwoDecimals(food.getCanadaPrice()),
food.getImage(),
food.getStore().getAvgRate()
roundToTwoDecimals(food.getStore().getAvgRate())
))
.collect(Collectors.toList());

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/kusitms/jipbap/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public void increaseReviewCount() {
}

public void updateAvgRate(Double newRate) {
this.avgRate = (avgRate*rateCount+newRate)/(++rateCount);
this.avgRate = roundToTwoDecimals((avgRate*rateCount+newRate)/(++rateCount));
}

private double roundToTwoDecimals(double value) {
return Math.round(value * 100) / 100.0;
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/kusitms/jipbap/store/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public StoreDto getMyStore(String email){
store.getName(),
store.getDescription(),
store.getKoreanYn(),
store.getAvgRate(),
roundToTwoDecimals(store.getAvgRate()),
roundToTwoDecimals(store.getMinOrderAmount()),
new String[]{store.getImage(), store.getImage2(), store.getImage3()}
);
Expand All @@ -134,7 +134,7 @@ public StoreFoodResponseDto searchStoresAndFoods(String email, Pageable pageable
List<StoreDetailResponseDto> storeList = storeRepository.searchByNameOrderBySort(user, pageable, keyword, standard, order)
.stream().map(s -> new StoreDetailResponseDto(
new StoreDto(
s.getId(), s.getName(), s.getDescription(), s.getKoreanYn(), s.getAvgRate(), roundToTwoDecimals(s.getMinOrderAmount()),
s.getId(), s.getName(), s.getDescription(), s.getKoreanYn(), roundToTwoDecimals(s.getAvgRate()), roundToTwoDecimals(s.getMinOrderAmount()),
new String[]{s.getImage(), s.getImage2(), s.getImage3()}
)
, storeBookmarkRepository.existsByUserAndStore(user, s)
Expand All @@ -144,7 +144,7 @@ public StoreFoodResponseDto searchStoresAndFoods(String email, Pageable pageable
.collect(Collectors.toList());

List<FoodPreviewResponse> foodList = foodRepository.searchByNameOrderBySort(user, pageable, keyword, standard, order)
.stream().map(f -> new FoodPreviewResponse(f.getId(), f.getName(), f.getStore().getId(), f.getStore().getName(), roundToTwoDecimals(f.getDollarPrice()), roundToTwoDecimals(f.getCanadaPrice()), f.getImage(), f.getStore().getAvgRate()))
.stream().map(f -> new FoodPreviewResponse(f.getId(), f.getName(), f.getStore().getId(), f.getStore().getName(), roundToTwoDecimals(f.getDollarPrice()), roundToTwoDecimals(f.getCanadaPrice()), f.getImage(), roundToTwoDecimals(f.getStore().getAvgRate())))
.collect(Collectors.toList());


Expand All @@ -164,7 +164,7 @@ public StoreDetailResponseDto getStoreDetail(String email, Long storeId) {
store.getName(),
store.getDescription(),
store.getKoreanYn(),
store.getAvgRate(),
roundToTwoDecimals(store.getAvgRate()),
roundToTwoDecimals(store.getMinOrderAmount()),
new String[]{store.getImage(), store.getImage2(), store.getImage3()}
)
Expand All @@ -188,7 +188,7 @@ public StoreDto bookmarkStore(String email, Long storeId) {
store.getName(),
store.getDescription(),
store.getKoreanYn(),
store.getAvgRate(),
roundToTwoDecimals(store.getAvgRate()),
roundToTwoDecimals(store.getMinOrderAmount()),
new String[]{store.getImage(), store.getImage2(), store.getImage3()}
);
Expand All @@ -208,7 +208,7 @@ public BookmarkedStoreListResponseDto findBookmarkedStore(String email) {
sb.getStore().getName(),
sb.getStore().getDescription(),
sb.getStore().getKoreanYn(),
sb.getStore().getAvgRate(),
roundToTwoDecimals(sb.getStore().getAvgRate()),
roundToTwoDecimals(sb.getStore().getMinOrderAmount()),
new String[]{sb.getStore().getImage(), sb.getStore().getImage2(), sb.getStore().getImage3()}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public StoreInfoDto(Store store) {
this.name = store.getName();
this.description = store.getDescription();
this.koreanYn = store.getKoreanYn();
this.avgRate = store.getAvgRate();
this.avgRate = roundToTwoDecimals(store.getAvgRate());
this.minOrderAmount = roundToTwoDecimals(store.getMinOrderAmount());
this.images = new String[]{store.getImage(), store.getImage2(), store.getImage3()};
this.address = store.getAddress();
Expand Down

0 comments on commit 9e6c70a

Please sign in to comment.