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; +}