From a528852e24d7108ea53f395c8d5e6324b45c1c94 Mon Sep 17 00:00:00 2001 From: summit45 Date: Sun, 19 Nov 2023 20:44:12 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B0=80=EA=B2=8C=EB=A7=88=EB=8B=A4=20?= =?UTF-8?q?=EB=A9=94=EB=89=B4=EB=B3=84=20=EC=A3=BC=EB=AC=B8=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20api=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kusitms/jipbap/order/OrderController.java | 12 +++-- .../kusitms/jipbap/order/OrderService.java | 45 +++++++++++++++++++ .../dto/ProcessingFoodDetailResponse.java | 16 +++++++ .../order/dto/ProcessingFoodResponse.java | 19 ++++++++ .../order/dto/StoreProcessingResponse.java | 17 +++++++ 5 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/kusitms/jipbap/order/dto/ProcessingFoodDetailResponse.java create mode 100644 src/main/java/com/kusitms/jipbap/order/dto/ProcessingFoodResponse.java create mode 100644 src/main/java/com/kusitms/jipbap/order/dto/StoreProcessingResponse.java diff --git a/src/main/java/com/kusitms/jipbap/order/OrderController.java b/src/main/java/com/kusitms/jipbap/order/OrderController.java index 057dd4f..7483496 100644 --- a/src/main/java/com/kusitms/jipbap/order/OrderController.java +++ b/src/main/java/com/kusitms/jipbap/order/OrderController.java @@ -1,10 +1,7 @@ package com.kusitms.jipbap.order; import com.kusitms.jipbap.common.response.CommonResponse; -import com.kusitms.jipbap.order.dto.OrderDto; -import com.kusitms.jipbap.order.dto.OrderFoodRequest; -import com.kusitms.jipbap.order.dto.OrderFoodResponse; -import com.kusitms.jipbap.order.dto.OrderHistoryResponse; +import com.kusitms.jipbap.order.dto.*; import com.kusitms.jipbap.security.Auth; import com.kusitms.jipbap.security.AuthInfo; import io.swagger.v3.oas.annotations.Operation; @@ -55,4 +52,11 @@ public CommonResponse processOrder( public CommonResponse> getMyOrderHistory(@Auth AuthInfo authInfo) { return new CommonResponse<>(orderService.getMyOrderHistory(authInfo.getEmail())); } + + @Operation(summary = "주문내역 중 진행 중인 메뉴 조회하기") + @GetMapping("/processing") + @ResponseStatus(HttpStatus.OK) + public CommonResponse getStoreProcessingOrder(@Auth AuthInfo authInfo) { + return new CommonResponse<>(orderService.getStoreProcessingOrder(authInfo.getEmail())); + } } diff --git a/src/main/java/com/kusitms/jipbap/order/OrderService.java b/src/main/java/com/kusitms/jipbap/order/OrderService.java index 9f59600..d357456 100644 --- a/src/main/java/com/kusitms/jipbap/order/OrderService.java +++ b/src/main/java/com/kusitms/jipbap/order/OrderService.java @@ -149,4 +149,49 @@ public List getMyOrderHistory(String email) { return orderFoodResponseList; } + public StoreProcessingResponse getStoreProcessingOrder(String email){ + User user = userRepository.findByEmail(email) + .orElseThrow(() -> new UserNotFoundException("해당 유저를 찾을 수 없습니다.")); + + Store store = storeRepository.findByOwner(user) + .orElseThrow(() -> new StoreNotExistsException("해당 유저의 가게를 찾을 수 없습니다.")); + + //전체 주문내역에서 해당 가게에 속하는 주문내역만 가져오기 + List orderList = orderRepository.findByStore_IdAndStatus(store.getId(), OrderStatus.ACCEPTED) + .orElseThrow(() -> new OrderNotExistsByOrderStatusException("해당 가게의 주문상태에 따른 주문 내역이 존재하지 않습니다.")); + + if (orderList.isEmpty()) { + throw new OrderNotExistsByOrderStatusException("해당 가게의 주문상태에 따른 주문 내역이 존재하지 않습니다."); + } + + //주문내역 중에서 음식별로 묶기 + List orderDetailList = orderList.stream() + .flatMap(order -> order.getOrderDetail().stream()) + .collect(Collectors.toList()); + + //음식 옵션별로 묶어서 음식별로 묶기 + List processingFoodResponseList = orderDetailList.stream() + .collect(Collectors.groupingBy(OrderDetail::getFood)) + .entrySet().stream() + .map(entry -> { + Food food = entry.getKey(); + List processingFoodDetailResponseList = entry.getValue().stream() + .collect(Collectors.groupingBy(OrderDetail::getFoodOption, + Collectors.summingLong(OrderDetail::getOrderCount))) + .entrySet().stream() + .map(entry2 -> new ProcessingFoodDetailResponse( + entry2.getKey().getId(), + entry2.getKey().getName(), + entry2.getValue())) + .collect(Collectors.toList()); + long totalOrderCount = processingFoodDetailResponseList.stream() + .mapToLong(ProcessingFoodDetailResponse::getOrderCount) + .sum(); + return new ProcessingFoodResponse(food.getId(), food.getName(), totalOrderCount, processingFoodDetailResponseList); + }) + .collect(Collectors.toList()); + + return new StoreProcessingResponse(orderList.size(), processingFoodResponseList); + + } } diff --git a/src/main/java/com/kusitms/jipbap/order/dto/ProcessingFoodDetailResponse.java b/src/main/java/com/kusitms/jipbap/order/dto/ProcessingFoodDetailResponse.java new file mode 100644 index 0000000..6039b40 --- /dev/null +++ b/src/main/java/com/kusitms/jipbap/order/dto/ProcessingFoodDetailResponse.java @@ -0,0 +1,16 @@ +package com.kusitms.jipbap.order.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class ProcessingFoodDetailResponse { + private Long foodOptionId; + private String foodOptionName; + private Long orderCount; +} diff --git a/src/main/java/com/kusitms/jipbap/order/dto/ProcessingFoodResponse.java b/src/main/java/com/kusitms/jipbap/order/dto/ProcessingFoodResponse.java new file mode 100644 index 0000000..e968b1c --- /dev/null +++ b/src/main/java/com/kusitms/jipbap/order/dto/ProcessingFoodResponse.java @@ -0,0 +1,19 @@ +package com.kusitms.jipbap.order.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class ProcessingFoodResponse { + private Long foodId; + private String foodName; + private Long totalOrderCount; + private List processingFoodDetailList; +} diff --git a/src/main/java/com/kusitms/jipbap/order/dto/StoreProcessingResponse.java b/src/main/java/com/kusitms/jipbap/order/dto/StoreProcessingResponse.java new file mode 100644 index 0000000..831985a --- /dev/null +++ b/src/main/java/com/kusitms/jipbap/order/dto/StoreProcessingResponse.java @@ -0,0 +1,17 @@ +package com.kusitms.jipbap.order.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class StoreProcessingResponse { + int orderCount; + List processingFoodList; +}