From 747759ad6f2b1af1436e670eb5db68462a03c077 Mon Sep 17 00:00:00 2001 From: summit45 Date: Thu, 23 Nov 2023 01:13:02 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=A7=84=ED=96=89=20=EC=A4=91=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8,=20=EC=98=A4=EB=8A=98=20=EC=A4=91=20?= =?UTF-8?q?=EC=A3=BC=EB=AC=B8=20api=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kusitms/jipbap/order/OrderController.java | 1 + .../kusitms/jipbap/order/OrderRepository.java | 7 +++++++ .../kusitms/jipbap/store/StoreController.java | 7 +++++++ .../kusitms/jipbap/store/StoreService.java | 20 +++++++++++++++++++ .../jipbap/store/dto/StoreManageResponse.java | 15 ++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 src/main/java/com/kusitms/jipbap/store/dto/StoreManageResponse.java diff --git a/src/main/java/com/kusitms/jipbap/order/OrderController.java b/src/main/java/com/kusitms/jipbap/order/OrderController.java index 7483496..e717d76 100644 --- a/src/main/java/com/kusitms/jipbap/order/OrderController.java +++ b/src/main/java/com/kusitms/jipbap/order/OrderController.java @@ -59,4 +59,5 @@ public CommonResponse> getMyOrderHistory(@Auth AuthIn public CommonResponse getStoreProcessingOrder(@Auth AuthInfo authInfo) { return new CommonResponse<>(orderService.getStoreProcessingOrder(authInfo.getEmail())); } + } diff --git a/src/main/java/com/kusitms/jipbap/order/OrderRepository.java b/src/main/java/com/kusitms/jipbap/order/OrderRepository.java index de09e40..8f2cad3 100644 --- a/src/main/java/com/kusitms/jipbap/order/OrderRepository.java +++ b/src/main/java/com/kusitms/jipbap/order/OrderRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import java.time.LocalDate; import java.util.List; import java.util.Optional; @@ -15,4 +16,10 @@ public interface OrderRepository extends JpaRepository { Optional> findByUser_Id(Long userId); + @Query("SELECT COUNT(o) FROM Order o WHERE DATE(o.createdAt) = :date") + Long countOrdersByDate(@Param("date") LocalDate date); + + @Query("SELECT COUNT(o) FROM Order o WHERE o.status = :status") + Long countOrdersByStatus(@Param("status") OrderStatus status); + } diff --git a/src/main/java/com/kusitms/jipbap/store/StoreController.java b/src/main/java/com/kusitms/jipbap/store/StoreController.java index cfd22ad..d5b417a 100644 --- a/src/main/java/com/kusitms/jipbap/store/StoreController.java +++ b/src/main/java/com/kusitms/jipbap/store/StoreController.java @@ -151,4 +151,11 @@ public CommonResponse getStoreInfoDetail(@Auth AuthInfo authI return new CommonResponse<>(storeService.getStoreInfoDetail(authInfo.getEmail(), storeId)); } + @Operation(summary = "주문관리에서 진행 중 주문과 오늘 총 주문 조회하기") + @GetMapping("/manage") + @ResponseStatus(HttpStatus.OK) + public CommonResponse getStoreManageOrder(@Auth AuthInfo authInfo) { + return new CommonResponse<>(storeService.getStoreManageOrder(authInfo.getEmail())); + } + } diff --git a/src/main/java/com/kusitms/jipbap/store/StoreService.java b/src/main/java/com/kusitms/jipbap/store/StoreService.java index de83b38..8cf32b4 100644 --- a/src/main/java/com/kusitms/jipbap/store/StoreService.java +++ b/src/main/java/com/kusitms/jipbap/store/StoreService.java @@ -8,6 +8,8 @@ import com.kusitms.jipbap.common.utils.S3Utils; import com.kusitms.jipbap.food.dto.FoodDto; import com.kusitms.jipbap.food.dto.FoodPreviewResponse; +import com.kusitms.jipbap.order.OrderRepository; +import com.kusitms.jipbap.order.OrderStatus; import com.kusitms.jipbap.store.dto.*; import com.kusitms.jipbap.store.exception.StoreExistsException; import com.kusitms.jipbap.store.exception.StoreNotExistsException; @@ -27,6 +29,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -41,6 +44,7 @@ public class StoreService { private final UserRepository userRepository; private final FoodRepository foodRepository; private final GlobalRegionRepository globalRegionRepository; + private final OrderRepository orderRepository; private final AmazonS3 amazonS3; @@ -256,6 +260,22 @@ public StoreInfoResponse getStoreInfoDetail(String email, Long storeId){ ); } + public StoreManageResponse getStoreManageOrder(String email){ + User user = userRepository.findByEmail(email) + .orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); + Store store = storeRepository.findByOwner(user) + .orElseThrow(()-> new StoreNotExistsException("가게 정보가 존재하지 않습니다.")); + + OrderStatus orderStatus = OrderStatus.ACCEPTED; + Long processingOrderCount = orderRepository.countOrdersByStatus(orderStatus); + Long todayOrderCount = orderRepository.countOrdersByDate(LocalDate.now()); + + + return new StoreManageResponse( + processingOrderCount, + todayOrderCount + ); + } private double roundToTwoDecimals(double value) { return Math.round(value * 100) / 100.0; } diff --git a/src/main/java/com/kusitms/jipbap/store/dto/StoreManageResponse.java b/src/main/java/com/kusitms/jipbap/store/dto/StoreManageResponse.java new file mode 100644 index 0000000..767fdc2 --- /dev/null +++ b/src/main/java/com/kusitms/jipbap/store/dto/StoreManageResponse.java @@ -0,0 +1,15 @@ +package com.kusitms.jipbap.store.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +public class StoreManageResponse { + private Long processingOrderCount; + private Long todayOrderCount; +}