diff --git a/src/main/java/com/kusitms/jipbap/food/Food.java b/src/main/java/com/kusitms/jipbap/food/Food.java index 320780d..d098799 100644 --- a/src/main/java/com/kusitms/jipbap/food/Food.java +++ b/src/main/java/com/kusitms/jipbap/food/Food.java @@ -33,8 +33,8 @@ public class Food extends DateEntity { @Column(name = "food_name") private String name; - private Long dollarPrice; - private Long canadaPrice; + private Double dollarPrice; + private Double canadaPrice; private String image; private String description; private String foodPackage; // 배달포장 모두 가능(ALL), 배달 가능(DELIVERY), 포장 가능(PACKAGE) diff --git a/src/main/java/com/kusitms/jipbap/food/FoodOption.java b/src/main/java/com/kusitms/jipbap/food/FoodOption.java index c678381..928490b 100644 --- a/src/main/java/com/kusitms/jipbap/food/FoodOption.java +++ b/src/main/java/com/kusitms/jipbap/food/FoodOption.java @@ -23,8 +23,7 @@ public class FoodOption { private String name; - private Long dollarPrice; - - private Long canadaPrice; + private Double dollarPrice; + private Double canadaPrice; } diff --git a/src/main/java/com/kusitms/jipbap/food/FoodService.java b/src/main/java/com/kusitms/jipbap/food/FoodService.java index f4ef23b..667c4c0 100644 --- a/src/main/java/com/kusitms/jipbap/food/FoodService.java +++ b/src/main/java/com/kusitms/jipbap/food/FoodService.java @@ -62,9 +62,14 @@ public CategoryDto registerCategory(RegisterCategoryRequestDto dto) { @Transactional public FoodDto registerFood(String email, RegisterFoodRequestDto dto, MultipartFile image, MultipartFile informationDescriptionImage) { - User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); - Store store = storeRepository.findByOwner(user).orElseThrow(()-> new StoreNotExistsException("해당 가게 id는 유효하지 않습니다.")); - Category category = categoryRepository.findById(dto.getCategoryId()).orElseThrow(()-> new CategoryNotExistsException("해당 카테고리 id는 유효하지 않습니다.")); + User user = userRepository.findByEmail(email) + .orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); + + Store store = storeRepository.findByOwner(user) + .orElseThrow(()-> new StoreNotExistsException("해당 가게 id는 유효하지 않습니다.")); + + Category category = categoryRepository.findById(dto.getCategoryId()) + .orElseThrow(()-> new CategoryNotExistsException("해당 카테고리 id는 유효하지 않습니다.")); String imageUri = null; String informationDescriptionImageUri = null; @@ -90,8 +95,8 @@ public FoodDto registerFood(String email, RegisterFoodRequestDto dto, MultipartF .store(store) .category(category) .name(dto.getName()) - .dollarPrice(dto.getDollarPrice()) - .canadaPrice(dto.getCanadaPrice()) + .dollarPrice(roundToTwoDecimals(dto.getDollarPrice())) + .canadaPrice(roundToTwoDecimals(dto.getCanadaPrice())) .image(imageUri) .description(dto.getDescription()) .foodPackage(dto.getFoodPackage()) @@ -107,8 +112,8 @@ public FoodDto registerFood(String email, RegisterFoodRequestDto dto, MultipartF FoodOption foodOption = FoodOption.builder() .food(food) .name(foodOptionRequest.getName()) - .dollarPrice(foodOptionRequest.getDollarPrice()) - .canadaPrice(foodOptionRequest.getCanadaPrice()) + .dollarPrice(roundToTwoDecimals(foodOptionRequest.getDollarPrice())) + .canadaPrice(roundToTwoDecimals(foodOptionRequest.getCanadaPrice())) .build(); foodOptionRepository.save(foodOption); @@ -130,8 +135,8 @@ public FoodDetailResponse getFoodDetail(Long foodId) { .storeName(food.getStore().getName()) .categoryId(food.getCategory().getId()) .name(food.getName()) - .dollarPrice(food.getDollarPrice()) - .canadaPrice(food.getCanadaPrice()) + .dollarPrice(roundToTwoDecimals(food.getDollarPrice())) + .canadaPrice(roundToTwoDecimals(food.getCanadaPrice())) .image(food.getImage()) .description(food.getDescription()) .foodPackage(food.getFoodPackage()) @@ -180,28 +185,13 @@ private List getBestSellingFoodByRegion(Long globalRegionId food.getName(), food.getStore().getId(), food.getStore().getName(), - food.getDollarPrice(), - food.getCanadaPrice(), + roundToTwoDecimals(food.getDollarPrice()), + roundToTwoDecimals(food.getCanadaPrice()), food.getImage(), food.getStore().getAvgRate() )) .collect(Collectors.toList()); -// List bestSellingFoodsInRegionList = orderRepository.findTop10BestSellingFoodsInRegion(globalRegionId); -// -// List bestSellingFoodResponseList = bestSellingFoodsInRegionList.stream() -// .map(food -> new FoodPreviewResponse ( -// food.getId(), -// food.getName(), -// food.getStore().getId(), -// food.getStore().getName(), -// food.getDollarPrice(), -// food.getCanadaPrice(), -// food.getImage(), -// food.getStore().getAvgRate() -// )) -// .collect(Collectors.toList()); -// return bestSellingFoodResponseList; } @@ -221,30 +211,14 @@ private List getLatestSellingFoodByRegion(Long globalRegion food.getName(), food.getStore().getId(), food.getStore().getName(), - food.getDollarPrice(), - food.getCanadaPrice(), + roundToTwoDecimals(food.getDollarPrice()), + roundToTwoDecimals(food.getCanadaPrice()), food.getImage(), food.getStore().getAvgRate() )) .collect(Collectors.toList()); return latestSellingFoodResponseList; -// List latestFoodsInRegionList = orderRepository.findLatestFoodsByRegionId(globalRegionId); -// -// List latestSellingFoodResponseList = latestFoodsInRegionList.stream() -// .map(food -> new FoodPreviewResponse( -// food.getId(), -// food.getName(), -// food.getStore().getId(), -// food.getStore().getName(), -// food.getDollarPrice(), -// food.getCanadaPrice(), -// food.getImage(), -// food.getStore().getAvgRate() -// )) -// .collect(Collectors.toList()); -// -// return latestSellingFoodResponseList; } public List getFoodByCategory(AuthInfo authInfo, Long categoryId, SortingType sortingType){ @@ -257,7 +231,6 @@ public List getFoodByCategory(AuthInfo authInfo, Long categ List foodList = foodRepository.findByStoreGlobalRegionAndCategory(globalRegion, category); - System.out.println("sortingType" + sortingType); foodList = sortFoodList(foodList, sortingType); List foodDtoList = foodList.stream() @@ -266,8 +239,8 @@ public List getFoodByCategory(AuthInfo authInfo, Long categ food.getName(), food.getStore().getId(), food.getStore().getName(), - food.getDollarPrice(), - food.getCanadaPrice(), + roundToTwoDecimals(food.getDollarPrice()), + roundToTwoDecimals(food.getCanadaPrice()), food.getImage(), food.getStore().getAvgRate() )) @@ -285,21 +258,24 @@ private List sortFoodList(List foodList, SortingType sortingType) { foodList.sort(Comparator.comparingDouble(food -> -food.getStore().getAvgRate())); break; case PRICE_HIGH: - foodList.sort(Comparator.comparingLong(Food::getDollarPrice).reversed()); + foodList.sort(Comparator.comparingDouble(Food::getDollarPrice).reversed()); break; case PRICE_LOW: - foodList.sort(Comparator.comparingLong(Food::getDollarPrice)); + foodList.sort(Comparator.comparingDouble(Food::getDollarPrice)); break; case RECENTLY_ADDED: foodList.sort(Comparator.comparing(Food::getCreatedAt).reversed()); break; default: // 기본은 추천 순으로 정렬 - // 추천 순으로 정렬할 기준이 없다면 아무 처리도 하지 않습니다. foodList.sort(Comparator.comparingLong(Food::getRecommendCount).reversed()); break; } return foodList; } + private double roundToTwoDecimals(double value) { + return Math.round(value * 100) / 100.0; + } + } diff --git a/src/main/java/com/kusitms/jipbap/food/dto/BestSellingFoodResponse.java b/src/main/java/com/kusitms/jipbap/food/dto/BestSellingFoodResponse.java index 0938cf4..3b421ed 100644 --- a/src/main/java/com/kusitms/jipbap/food/dto/BestSellingFoodResponse.java +++ b/src/main/java/com/kusitms/jipbap/food/dto/BestSellingFoodResponse.java @@ -8,12 +8,24 @@ @Getter @Setter @NoArgsConstructor -@AllArgsConstructor public class BestSellingFoodResponse { private Long foodId; private String name; private String storeName; - private Long dollarPrice; - private Long canadaPrice; + private Double dollarPrice; + private Double canadaPrice; private Double avgRate; + + public BestSellingFoodResponse(Long foodId, String name, String storeName, Double dollarPrice, Double canadaPrice, Double avgRate) { + this.foodId = foodId; + this.name = name; + this.storeName = storeName; + this.dollarPrice = roundToTwoDecimals(dollarPrice); + this.canadaPrice = roundToTwoDecimals(canadaPrice); + this.avgRate = roundToTwoDecimals(avgRate); + } + + private double roundToTwoDecimals(double value) { + return Math.round(value * 100) / 100.0; + } } diff --git a/src/main/java/com/kusitms/jipbap/food/dto/FoodDetailByStoreResponse.java b/src/main/java/com/kusitms/jipbap/food/dto/FoodDetailByStoreResponse.java index a8e2bed..3c2e650 100644 --- a/src/main/java/com/kusitms/jipbap/food/dto/FoodDetailByStoreResponse.java +++ b/src/main/java/com/kusitms/jipbap/food/dto/FoodDetailByStoreResponse.java @@ -15,8 +15,8 @@ public class FoodDetailByStoreResponse { private Long id; private Long categoryId; private String name; - private Long dollarPrice; - private Long canadaPrice; + private Double dollarPrice; + private Double canadaPrice; private String description; private Long recommendCount; private String image; @@ -25,10 +25,14 @@ public FoodDetailByStoreResponse(Food food){ this.id = food.getId(); this.categoryId = food.getCategory().getId(); this.name = food.getName(); - this.dollarPrice = food.getDollarPrice(); - this.canadaPrice = food.getCanadaPrice(); + this.dollarPrice = roundToTwoDecimals(food.getDollarPrice()); + this.canadaPrice = roundToTwoDecimals(food.getCanadaPrice()); this.description = food.getDescription(); this.recommendCount = food.getRecommendCount(); this.image = food.getImage(); } + + private double roundToTwoDecimals(double value) { + return Math.round(value * 100) / 100.0; + } } diff --git a/src/main/java/com/kusitms/jipbap/food/dto/FoodDetailResponse.java b/src/main/java/com/kusitms/jipbap/food/dto/FoodDetailResponse.java index f408752..b300c13 100644 --- a/src/main/java/com/kusitms/jipbap/food/dto/FoodDetailResponse.java +++ b/src/main/java/com/kusitms/jipbap/food/dto/FoodDetailResponse.java @@ -15,13 +15,13 @@ public class FoodDetailResponse { private String storeName; private Long categoryId; private String name; - private Long dollarPrice; - private Long canadaPrice; + private Double dollarPrice; + private Double canadaPrice; private String image; private String description; private String foodPackage; private String informationDescription; private String ingredient; - private Long minOrderAmount; // 최소 주문 금액 추가 + private Double minOrderAmount; // 최소 주문 금액 추가 private List foodOptionResponseList; } diff --git a/src/main/java/com/kusitms/jipbap/food/dto/FoodDto.java b/src/main/java/com/kusitms/jipbap/food/dto/FoodDto.java index eeaa5b8..a0ba7db 100644 --- a/src/main/java/com/kusitms/jipbap/food/dto/FoodDto.java +++ b/src/main/java/com/kusitms/jipbap/food/dto/FoodDto.java @@ -15,8 +15,8 @@ public class FoodDto { private Long storeId; private Long categoryId; private String name; - private Long dollarPrice; - private Long canadaPrice; + private Double dollarPrice; + private Double canadaPrice; private String description; private String image; diff --git a/src/main/java/com/kusitms/jipbap/food/dto/FoodOptionRequest.java b/src/main/java/com/kusitms/jipbap/food/dto/FoodOptionRequest.java index ff8c05b..4179fec 100644 --- a/src/main/java/com/kusitms/jipbap/food/dto/FoodOptionRequest.java +++ b/src/main/java/com/kusitms/jipbap/food/dto/FoodOptionRequest.java @@ -12,7 +12,7 @@ public class FoodOptionRequest { private String name; - private Long dollarPrice; + private Double dollarPrice; - private Long canadaPrice; + private Double canadaPrice; } diff --git a/src/main/java/com/kusitms/jipbap/food/dto/FoodOptionResponse.java b/src/main/java/com/kusitms/jipbap/food/dto/FoodOptionResponse.java index b24e3cb..5443b3e 100644 --- a/src/main/java/com/kusitms/jipbap/food/dto/FoodOptionResponse.java +++ b/src/main/java/com/kusitms/jipbap/food/dto/FoodOptionResponse.java @@ -12,6 +12,6 @@ public class FoodOptionResponse { private Long id; private String name; - private Long dollarPrice; - private Long canadaPrice; + private Double dollarPrice; + private Double canadaPrice; } diff --git a/src/main/java/com/kusitms/jipbap/food/dto/FoodPreviewResponse.java b/src/main/java/com/kusitms/jipbap/food/dto/FoodPreviewResponse.java index 3ddf604..99bffa5 100644 --- a/src/main/java/com/kusitms/jipbap/food/dto/FoodPreviewResponse.java +++ b/src/main/java/com/kusitms/jipbap/food/dto/FoodPreviewResponse.java @@ -14,8 +14,8 @@ public class FoodPreviewResponse { private String name; private Long storeId; private String storeName; - private Long dollarPrice; - private Long canadaPrice; + private Double dollarPrice; + private Double canadaPrice; private String image; private Double avgRate; } diff --git a/src/main/java/com/kusitms/jipbap/food/dto/RegisterFoodRequestDto.java b/src/main/java/com/kusitms/jipbap/food/dto/RegisterFoodRequestDto.java index 62aa1c1..b79f06b 100644 --- a/src/main/java/com/kusitms/jipbap/food/dto/RegisterFoodRequestDto.java +++ b/src/main/java/com/kusitms/jipbap/food/dto/RegisterFoodRequestDto.java @@ -22,8 +22,8 @@ public class RegisterFoodRequestDto { private Long categoryId; @NotBlank private String name; - private Long dollarPrice; - private Long canadaPrice; + private Double dollarPrice; + private Double canadaPrice; @NotBlank private String description; private List foodOptionRequestList; diff --git a/src/main/java/com/kusitms/jipbap/order/Order.java b/src/main/java/com/kusitms/jipbap/order/Order.java index e86cecb..d4ebdeb 100644 --- a/src/main/java/com/kusitms/jipbap/order/Order.java +++ b/src/main/java/com/kusitms/jipbap/order/Order.java @@ -34,7 +34,7 @@ public class Order extends DateEntity { private Store store; @NotNull - private Long totalPrice; //총 주문 결제 금액 + private Double totalPrice; //총 주문 결제 금액 private Long totalCount; //총 주문한 메뉴 개수 @NotNull diff --git a/src/main/java/com/kusitms/jipbap/order/OrderDetail.java b/src/main/java/com/kusitms/jipbap/order/OrderDetail.java index b0d90a7..d1c5fcf 100644 --- a/src/main/java/com/kusitms/jipbap/order/OrderDetail.java +++ b/src/main/java/com/kusitms/jipbap/order/OrderDetail.java @@ -32,7 +32,7 @@ public class OrderDetail { private Long orderCount; //품목 개수 @NotNull - private Long orderAmount; //품목당 가격 + private Double orderAmount; //품목당 가격 @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "order_id") diff --git a/src/main/java/com/kusitms/jipbap/order/OrderService.java b/src/main/java/com/kusitms/jipbap/order/OrderService.java index d61eaf7..b8970b0 100644 --- a/src/main/java/com/kusitms/jipbap/order/OrderService.java +++ b/src/main/java/com/kusitms/jipbap/order/OrderService.java @@ -37,7 +37,6 @@ public class OrderService { private final UserRepository userRepository; private final FoodRepository foodRepository; private final FoodOptionRepository foodOptionRepository; - private final NotificationRepository notificationRepository; private final StoreRepository storeRepository; private final FCMNotificationService fcmNotificationService; @@ -47,12 +46,11 @@ public OrderFoodResponse orderFood(String email, OrderFoodRequest dto) { .orElseThrow(() -> new UserNotFoundException("해당 유저를 찾을 수 없습니다.")); Store store = storeRepository.findById(dto.getStore()) .orElseThrow(()-> new StoreNotExistsException("해당 가게는 존재하지 않습니다.")); - Order order = orderRepository.save( Order.builder() .user(user) .store(store) - .totalPrice(dto.getTotalPrice()) + .totalPrice(roundToTwoDecimals(dto.getTotalPrice())) .totalCount(dto.getTotalCount()) .regionId(user.getGlobalRegion().getId()) .selectedOption(dto.getSelectedOption()) @@ -76,6 +74,7 @@ public OrderFoodResponse orderFood(String email, OrderFoodRequest dto) { public List saveOrderFoodDetail(Long orderId, List orderFoodDetailList) { Order order = orderRepository.findById(orderId) .orElseThrow(() -> new OrderNotFoundException("주문 아이디를 찾을 수 없습니다.")); + return orderFoodDetailList.stream() .map(item -> { Food food = foodRepository.findById(item.getFoodId()) @@ -86,7 +85,7 @@ public List saveOrderFoodDetail(Long orderId, List new UserNotFoundException("해당 유저를 찾을 수 없습니다.")); - Store store = storeRepository.findByOwner(user) .orElseThrow(() -> new StoreNotExistsException("해당 유저의 가게를 찾을 수 없습니다.")); @@ -148,7 +146,6 @@ public void processOrder(String email, Long orderId, String status) { FCMRequestDto dto = new FCMRequestDto(buyer.getId(), "가게가 주문을 수락했습니다.", "맛있는 한식 집밥이 곧 찾아갑니다!"); String ans = fcmNotificationService.sendNotificationByToken(dto); log.info("판매자가 주문을 수락, 구매자에게 알림 전송 결과: " + ans); - } else if(newStatus.equals(OrderStatus.REJECTED)) { //판매자가 주문을 취소함 FCMRequestDto dto = new FCMRequestDto(buyer.getId(), "가게가 주문을 취소했습니다.", "다른 상품을 주문해 주세요."); @@ -220,4 +217,8 @@ public StoreProcessingResponse getStoreProcessingOrder(String email) { } return new StoreProcessingResponse(orderList.size(), processingFoodResponseList); } + + private double roundToTwoDecimals(double value) { + return Math.round(value * 100) / 100.0; + } } diff --git a/src/main/java/com/kusitms/jipbap/order/dto/OrderDto.java b/src/main/java/com/kusitms/jipbap/order/dto/OrderDto.java index 0bf3510..5f83185 100644 --- a/src/main/java/com/kusitms/jipbap/order/dto/OrderDto.java +++ b/src/main/java/com/kusitms/jipbap/order/dto/OrderDto.java @@ -18,18 +18,14 @@ public class OrderDto { private Long id; private Long user; - //private Long food; - //private Long orderCount; - private Long totalPrice; + private Double totalPrice; private String orderedAt; private String status; public OrderDto(Order order) { this.id = order.getId(); this.user = order.getUser().getId(); -// this.food = order.getFood().getId(); -// this.orderCount = order.getOrderCount(); - this.totalPrice = order.getTotalPrice(); + this.totalPrice = roundToTwoDecimals(order.getTotalPrice()); this.orderedAt = setOrderedAt(order.getCreatedAt()); this.status = order.getStatus().toString(); } @@ -38,4 +34,8 @@ private String setOrderedAt(LocalDateTime localDateTime) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); return localDateTime.format(formatter); } + + private double roundToTwoDecimals(double value) { + return Math.round(value * 100) / 100.0; + } } diff --git a/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodDetailRequest.java b/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodDetailRequest.java index 8e0eb43..013ed01 100644 --- a/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodDetailRequest.java +++ b/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodDetailRequest.java @@ -13,5 +13,5 @@ public class OrderFoodDetailRequest { private Long foodId; private Long foodOptionId; private Long orderCount; - private Long orderAmount; + private Double orderAmount; } diff --git a/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodDetailResponse.java b/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodDetailResponse.java index 75f6f5b..b2b486e 100644 --- a/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodDetailResponse.java +++ b/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodDetailResponse.java @@ -18,7 +18,7 @@ public class OrderFoodDetailResponse { private Long foodOptionId; //foodOptionId로 설정 private String foodOptionName; private Long orderCount; //품목 개수 - private Long orderAmount; //품목당 가격 + private Double orderAmount; //품목당 가격 public OrderFoodDetailResponse(OrderDetail orderDetail){ this.orderDetailId = orderDetail.getId(); @@ -27,6 +27,10 @@ public OrderFoodDetailResponse(OrderDetail orderDetail){ this.foodOptionId = orderDetail.getFoodOption().getId(); this.foodOptionName = orderDetail.getFoodOption().getName(); this.orderCount = orderDetail.getOrderCount(); - this.orderAmount = orderDetail.getOrderAmount(); + this.orderAmount = roundToTwoDecimals(orderDetail.getOrderAmount()); + } + + private double roundToTwoDecimals(double value) { + return Math.round(value * 100) / 100.0; } } diff --git a/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodRequest.java b/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodRequest.java index 28ae135..7ddaaa3 100644 --- a/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodRequest.java +++ b/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodRequest.java @@ -13,7 +13,7 @@ @NoArgsConstructor public class OrderFoodRequest { private Long store; - private Long totalPrice; + private Double totalPrice; private Long totalCount; private String selectedOption; private List orderFoodDetailList; diff --git a/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodResponse.java b/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodResponse.java index 306b41a..3b9d850 100644 --- a/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodResponse.java +++ b/src/main/java/com/kusitms/jipbap/order/dto/OrderFoodResponse.java @@ -21,7 +21,7 @@ public class OrderFoodResponse { private Long userId; private Long storeId; private Long totalCount; - private Long totalPrice; + private Double totalPrice; private String selectedOption; private String orderedAt; private String status; @@ -32,7 +32,7 @@ public OrderFoodResponse(Order order){ this.userId = order.getUser().getId(); this.storeId = order.getStore().getId(); this.totalCount = order.getTotalCount(); - this.totalPrice = order.getTotalPrice(); + this.totalPrice = roundToTwoDecimals(order.getTotalPrice()); this.selectedOption = order.getSelectedOption(); this.orderedAt = setOrderedAt(order.getCreatedAt()); this.orderFoodDetailList = setOrderFoodDetailList(order.getOrderDetail()); @@ -48,4 +48,9 @@ private List setOrderFoodDetailList(List o return new OrderFoodDetailResponse(item); }).collect(Collectors.toList()); } + + private double roundToTwoDecimals(double value) { + return Math.round(value * 100) / 100.0; + } + } diff --git a/src/main/java/com/kusitms/jipbap/order/dto/OrderHistoryResponse.java b/src/main/java/com/kusitms/jipbap/order/dto/OrderHistoryResponse.java index 2ef5697..c347f18 100644 --- a/src/main/java/com/kusitms/jipbap/order/dto/OrderHistoryResponse.java +++ b/src/main/java/com/kusitms/jipbap/order/dto/OrderHistoryResponse.java @@ -26,7 +26,7 @@ public class OrderHistoryResponse { private String storeImage2; private String storeImage3; private Long totalCount; - private Long totalPrice; + private Double totalPrice; private String selectedOption; //배달 포장 private String orderedAt; private String status; @@ -42,7 +42,7 @@ public OrderHistoryResponse(Order order){ this.storeImage2 = order.getStore().getImage2(); this.storeImage3 = order.getStore().getImage3(); this.totalCount = order.getTotalCount(); - this.totalPrice = order.getTotalPrice(); + this.totalPrice = roundToTwoDecimals(order.getTotalPrice()); this.selectedOption = order.getSelectedOption(); this.orderedAt = setOrderedAt(order.getCreatedAt()); this.orderFoodDetailList = setOrderFoodDetailList(order.getOrderDetail()); @@ -66,4 +66,9 @@ private Boolean isReviwed(Review review) { } return true; } + + private double roundToTwoDecimals(double value) { + return Math.round(value * 100) / 100.0; + } + } diff --git a/src/main/java/com/kusitms/jipbap/store/Store.java b/src/main/java/com/kusitms/jipbap/store/Store.java index b8b4f94..46ec490 100644 --- a/src/main/java/com/kusitms/jipbap/store/Store.java +++ b/src/main/java/com/kusitms/jipbap/store/Store.java @@ -48,7 +48,7 @@ public class Store extends DateEntity { @Column(columnDefinition = "TINYINT(1)", name="korean_yn") private Boolean koreanYn; //한국인 인증 여부 - private Long minOrderAmount; //최소 주문 금액 + private Double minOrderAmount; //최소 주문 금액 private String image; private String image2; private String image3; diff --git a/src/main/java/com/kusitms/jipbap/store/StoreService.java b/src/main/java/com/kusitms/jipbap/store/StoreService.java index 5d27c4b..7dc9b46 100644 --- a/src/main/java/com/kusitms/jipbap/store/StoreService.java +++ b/src/main/java/com/kusitms/jipbap/store/StoreService.java @@ -76,7 +76,7 @@ public RegisterStoreResponse registerStore(String email, RegisterStoreRequestDto .name(dto.getName()) .description(dto.getDescription()) .koreanYn(dto.getKoreanYn()) - .minOrderAmount(dto.getMinOrderAmount()) + .minOrderAmount(roundToTwoDecimals(dto.getMinOrderAmount())) .image(imageUri[0]) .image2(imageUri[1]) .image3(imageUri[2]) @@ -100,8 +100,10 @@ public RegisterStoreResponse registerStore(String email, RegisterStoreRequestDto } public StoreDto getMyStore(String email){ - User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); - Store store = storeRepository.findByOwner(user).orElseThrow(()-> new StoreNotExistsException("가게 정보가 존재하지 않습니다.")); + User user = userRepository.findByEmail(email) + .orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); + Store store = storeRepository.findByOwner(user) + .orElseThrow(()-> new StoreNotExistsException("가게 정보가 존재하지 않습니다.")); return new StoreDto( store.getId(), @@ -109,14 +111,15 @@ public StoreDto getMyStore(String email){ store.getDescription(), store.getKoreanYn(), store.getAvgRate(), - store.getMinOrderAmount(), + roundToTwoDecimals(store.getMinOrderAmount()), new String[]{store.getImage(), store.getImage2(), store.getImage3()} ); } @Transactional public Slice searchStoreList(String email, Pageable pageable, String keyword, String standard, String order, Long lastId) { - User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); + User user = userRepository.findByEmail(email) + .orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); if(lastId!=null) storeRepository.findById(lastId).orElseThrow(()-> new StoreNotExistsException("lastId: "+lastId+"에 해당하는 가게가 존재하지 않습니다.")); @@ -125,12 +128,13 @@ public Slice searchStoreList(String email, Pageable page @Transactional public StoreFoodResponseDto searchStoresAndFoods(String email, Pageable pageable, String keyword, String standard, String order) { - User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); + User user = userRepository.findByEmail(email) + .orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); List 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(), s.getMinOrderAmount(), + s.getId(), s.getName(), s.getDescription(), s.getKoreanYn(), s.getAvgRate(), roundToTwoDecimals(s.getMinOrderAmount()), new String[]{s.getImage(), s.getImage2(), s.getImage3()} ) , storeBookmarkRepository.existsByUserAndStore(user, s) @@ -140,7 +144,7 @@ public StoreFoodResponseDto searchStoresAndFoods(String email, Pageable pageable .collect(Collectors.toList()); List foodList = foodRepository.searchByNameOrderBySort(user, pageable, keyword, standard, order) - .stream().map(f -> new FoodPreviewResponse(f.getId(), f.getName(), f.getStore().getId(), f.getStore().getName(), f.getDollarPrice(), 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(), f.getStore().getAvgRate())) .collect(Collectors.toList()); @@ -149,9 +153,10 @@ public StoreFoodResponseDto searchStoresAndFoods(String email, Pageable pageable @Transactional public StoreDetailResponseDto getStoreDetail(String email, Long storeId) { - User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); - - Store store = storeRepository.findById(storeId).orElseThrow(()-> new StoreNotExistsException("storeId: "+storeId+"에 해당하는 가게가 존재하지 않습니다.")); + User user = userRepository.findByEmail(email) + .orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); + Store store = storeRepository.findById(storeId) + .orElseThrow(()-> new StoreNotExistsException("storeId: "+storeId+"에 해당하는 가게가 존재하지 않습니다.")); return new StoreDetailResponseDto( new StoreDto( @@ -160,7 +165,7 @@ public StoreDetailResponseDto getStoreDetail(String email, Long storeId) { store.getDescription(), store.getKoreanYn(), store.getAvgRate(), - store.getMinOrderAmount(), + roundToTwoDecimals(store.getMinOrderAmount()), new String[]{store.getImage(), store.getImage2(), store.getImage3()} ) , isStoreBookmarked(user, store) @@ -170,8 +175,10 @@ public StoreDetailResponseDto getStoreDetail(String email, Long storeId) { @Transactional public StoreDto bookmarkStore(String email, Long storeId) { - User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); - Store store = storeRepository.findById(storeId).orElseThrow(()-> new StoreNotExistsException("storeId: "+storeId+"에 해당하는 가게가 존재하지 않습니다.")); + User user = userRepository.findByEmail(email) + .orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); + Store store = storeRepository.findById(storeId) + .orElseThrow(()-> new StoreNotExistsException("storeId: "+storeId+"에 해당하는 가게가 존재하지 않습니다.")); storeBookmarkRepository.save(new StoreBookmark(null, user, store)); store.increaseBookmarkCount(); @@ -182,19 +189,19 @@ public StoreDto bookmarkStore(String email, Long storeId) { store.getDescription(), store.getKoreanYn(), store.getAvgRate(), - store.getMinOrderAmount(), + roundToTwoDecimals(store.getMinOrderAmount()), new String[]{store.getImage(), store.getImage2(), store.getImage3()} ); } @Transactional public BookmarkedStoreListResponseDto findBookmarkedStore(String email) { - User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); + User user = userRepository.findByEmail(email) + .orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); List storeBookmarks = storeBookmarkRepository.findByUser(user); List sbList = new ArrayList<>(); - for (StoreBookmark sb : storeBookmarks) { sbList.add(new StoreDto( sb.getId(), @@ -202,7 +209,7 @@ public BookmarkedStoreListResponseDto findBookmarkedStore(String email) { sb.getStore().getDescription(), sb.getStore().getKoreanYn(), sb.getStore().getAvgRate(), - sb.getStore().getMinOrderAmount(), + roundToTwoDecimals(sb.getStore().getMinOrderAmount()), new String[]{sb.getStore().getImage(), sb.getStore().getImage2(), sb.getStore().getImage3()} ) ); @@ -217,7 +224,6 @@ private Boolean isStoreBookmarked(User user, Store store){ public List getAllMenuListByStoreId(Long storeId) { //유효한 storeId인지 검사 - Store store = storeRepository.findById(storeId).orElseThrow(()-> new StoreNotExistsException("storeId: " + storeId + "에 해당하는 가게가 존재하지 않습니다.")); List foodList = foodRepository.findAllByStore(store); @@ -229,8 +235,10 @@ public List getAllMenuListByStoreId(Long storeId) { } public List getMyStoreMenu(String email){ - User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); - Store store = storeRepository.findByOwner(user).orElseThrow(()-> new StoreNotExistsException("가게 정보가 존재하지 않습니다.")); + User user = userRepository.findByEmail(email) + .orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); + Store store = storeRepository.findByOwner(user) + .orElseThrow(()-> new StoreNotExistsException("가게 정보가 존재하지 않습니다.")); return getAllMenuListByStoreId(store.getId()); } @@ -247,4 +255,9 @@ public StoreInfoResponse getStoreInfoDetail(String email, Long storeId){ store.getFoodChangeYn() ); } + + private double roundToTwoDecimals(double value) { + return Math.round(value * 100) / 100.0; + } + } diff --git a/src/main/java/com/kusitms/jipbap/store/dto/RegisterStoreRequestDto.java b/src/main/java/com/kusitms/jipbap/store/dto/RegisterStoreRequestDto.java index 1225a9a..680ac77 100644 --- a/src/main/java/com/kusitms/jipbap/store/dto/RegisterStoreRequestDto.java +++ b/src/main/java/com/kusitms/jipbap/store/dto/RegisterStoreRequestDto.java @@ -16,7 +16,7 @@ public class RegisterStoreRequestDto { private String name; @NotBlank - private Long minOrderAmount; + private Double minOrderAmount; @NotBlank private String description; diff --git a/src/main/java/com/kusitms/jipbap/store/dto/StoreDto.java b/src/main/java/com/kusitms/jipbap/store/dto/StoreDto.java index 41eda57..7030405 100644 --- a/src/main/java/com/kusitms/jipbap/store/dto/StoreDto.java +++ b/src/main/java/com/kusitms/jipbap/store/dto/StoreDto.java @@ -16,6 +16,6 @@ public class StoreDto { private String description; private Boolean koreanYn; private Double avgRate; // 가게 평점 - private Long minOrderAmount; //최소 주문 금액 + private Double minOrderAmount; //최소 주문 금액 private String[] images; } diff --git a/src/main/java/com/kusitms/jipbap/store/dto/StoreInfoDto.java b/src/main/java/com/kusitms/jipbap/store/dto/StoreInfoDto.java index 26a95bd..8761a96 100644 --- a/src/main/java/com/kusitms/jipbap/store/dto/StoreInfoDto.java +++ b/src/main/java/com/kusitms/jipbap/store/dto/StoreInfoDto.java @@ -14,7 +14,7 @@ public class StoreInfoDto { private String description; private Boolean koreanYn; private Double avgRate; // 가게 평점 - private Long minOrderAmount; //최소 주문 금액 + private Double minOrderAmount; //최소 주문 금액 private String[] images; private String address; private String detailAddress; @@ -28,7 +28,7 @@ public StoreInfoDto(Store store) { this.description = store.getDescription(); this.koreanYn = store.getKoreanYn(); this.avgRate = store.getAvgRate(); - this.minOrderAmount = store.getMinOrderAmount(); + this.minOrderAmount = roundToTwoDecimals(store.getMinOrderAmount()); this.images = new String[]{store.getImage(), store.getImage2(), store.getImage3()}; this.address = store.getAddress(); this.detailAddress = store.getDetailAddress(); @@ -36,4 +36,9 @@ public StoreInfoDto(Store store) { this.deliveryRegion = store.getDeliveryRegion(); this.operationTime = store.getOperationTime(); } + + private double roundToTwoDecimals(double value) { + return Math.round(value * 100) / 100.0; + } + }