diff --git a/src/main/java/com/jangburich/domain/order/domain/repository/OrdersRepository.java b/src/main/java/com/jangburich/domain/order/domain/repository/OrdersRepository.java index 23097c9..dbfa9bc 100644 --- a/src/main/java/com/jangburich/domain/order/domain/repository/OrdersRepository.java +++ b/src/main/java/com/jangburich/domain/order/domain/repository/OrdersRepository.java @@ -23,4 +23,16 @@ List findOrdersByStoreAndDateAndStatusNative( @Param("updatedAt") LocalDateTime updatedAt, @Param("orderStatus") String orderStatus); + @Query("SELECT o FROM Orders o " + + "WHERE o.store.id = :storeId " + + "AND o.updatedAt >= :startOfDay " + + "AND o.updatedAt < :endOfDay " + + "AND o.orderStatus = :orderStatus") + List findOrdersByStoreAndTodayDateAndStatus( + @Param("storeId") Long storeId, + @Param("startOfDay") LocalDateTime startOfDay, + @Param("endOfDay") LocalDateTime endOfDay, + @Param("orderStatus") OrderStatus orderStatus); + + } diff --git a/src/main/java/com/jangburich/domain/store/controller/StoreController.java b/src/main/java/com/jangburich/domain/store/controller/StoreController.java index 7bbd9c2..91b8fbf 100644 --- a/src/main/java/com/jangburich/domain/store/controller/StoreController.java +++ b/src/main/java/com/jangburich/domain/store/controller/StoreController.java @@ -28,6 +28,7 @@ import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; import com.jangburich.domain.store.dto.response.OrdersDetailResponse; import com.jangburich.domain.store.dto.response.OrdersGetResponse; +import com.jangburich.domain.store.dto.response.OrdersTodayResponse; import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse; import com.jangburich.domain.store.dto.response.SearchStoresResponse; import com.jangburich.domain.store.service.StoreService; @@ -118,12 +119,19 @@ public ResponseCustom getPaymentHistory(Authentication authentication, Pageab @Operation(summary = "지난 주문 조회", description = "가게에 있는 지난 주문을 조회합니다") @GetMapping("/orders/last") - public ResponseCustom> getOrders(Authentication authentication) { + public ResponseCustom> getLastOrders(Authentication authentication) { List ordersLast = storeService.getOrdersLast( AuthenticationParser.parseUserId(authentication)); return ResponseCustom.OK(ordersLast); } + @Operation(summary = "오늘 주문 조회", description = "가게에 있는 오늘 주문을 조회합니다") + @GetMapping("/orders/today") + public ResponseCustom getTodayOrders(Authentication authentication) { + return ResponseCustom.OK(storeService.getTodayOrders( + AuthenticationParser.parseUserId(authentication))); + } + @Operation(summary = "주문 상세 조회", description = "가게에 있는 주문을 상세 조회합니다") @GetMapping("/orders/{ordersId}") public ResponseCustom getOrders(Authentication authentication, @RequestParam Long orderId) { diff --git a/src/main/java/com/jangburich/domain/store/dto/response/OrdersTodayResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/OrdersTodayResponse.java new file mode 100644 index 0000000..6f53752 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/dto/response/OrdersTodayResponse.java @@ -0,0 +1,13 @@ +package com.jangburich.domain.store.dto.response; + +import java.util.List; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class OrdersTodayResponse { + private Integer totalPrice; + private List ordersGetResponses; +} diff --git a/src/main/java/com/jangburich/domain/store/service/StoreService.java b/src/main/java/com/jangburich/domain/store/service/StoreService.java index 7dc9ec3..b5b695c 100644 --- a/src/main/java/com/jangburich/domain/store/service/StoreService.java +++ b/src/main/java/com/jangburich/domain/store/service/StoreService.java @@ -15,6 +15,7 @@ import com.jangburich.domain.menu.domain.MenuCreateRequestDTO; import com.jangburich.domain.menu.repository.MenuRepository; import com.jangburich.domain.order.domain.Cart; +import com.jangburich.domain.order.domain.OrderStatus; import com.jangburich.domain.order.domain.Orders; import com.jangburich.domain.order.domain.repository.CartRepository; import com.jangburich.domain.order.domain.repository.OrdersRepository; @@ -35,6 +36,7 @@ import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; import com.jangburich.domain.store.dto.response.OrdersDetailResponse; import com.jangburich.domain.store.dto.response.OrdersGetResponse; +import com.jangburich.domain.store.dto.response.OrdersTodayResponse; import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse; import com.jangburich.domain.store.dto.response.SearchStoresResponse; import com.jangburich.domain.store.exception.OrdersNotFoundException; @@ -274,10 +276,10 @@ public List getOrdersLast(String userId) { List carts = cartRepository.findAllByOrders(orders); newOrdersGetResponse.setId(orders.getId()); newOrdersGetResponse.setMenuNames(carts.size() == 1 ? carts.get(0).getMenu().getName() : - carts.get(0).getMenu().getName() + "외 " + (carts.size() - 1) + "개"); + carts.get(0).getMenu().getName() + " 외 " + (carts.size() - 1) + "개"); newOrdersGetResponse.setCount(carts.size()); newOrdersGetResponse.setDate(orders.getUpdatedAt()); - Integer price = 0; + int price = 0; for (Cart cart : carts) { price += (cart.getMenu().getPrice() * cart.getQuantity()); } @@ -288,6 +290,49 @@ public List getOrdersLast(String userId) { return ordersGetResponses; } + public OrdersTodayResponse getTodayOrders(String userId) { + List ordersGetResponses = new ArrayList<>(); + + User user = userRepository.findByProviderId(userId) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Owner owner = ownerRepository.findByUser(user) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Store store = storeRepository.findByOwner(owner) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + LocalDateTime startOfDay = LocalDate.now().atStartOfDay(); // 오늘 시작 + LocalDateTime endOfDay = LocalDate.now().plusDays(1).atStartOfDay(); // 내일 시작 (오늘의 끝) + + List allByStore = ordersRepository.findOrdersByStoreAndTodayDateAndStatus( + store.getId(), startOfDay, endOfDay, OrderStatus.TICKET_USED); + int totalPrice = 0; + for (Orders orders : allByStore) { + OrdersGetResponse newOrdersGetResponse = new OrdersGetResponse(); + List carts = cartRepository.findAllByOrders(orders); + + newOrdersGetResponse.setId(orders.getId()); + newOrdersGetResponse.setMenuNames(carts.size() == 1 ? carts.get(0).getMenu().getName() : + carts.get(0).getMenu().getName() + " 외 " + (carts.size() - 1) + "개"); + newOrdersGetResponse.setCount(carts.size()); + newOrdersGetResponse.setDate(orders.getUpdatedAt()); + int price = 0; + for (Cart cart : carts) { + price += (cart.getMenu().getPrice() * cart.getQuantity()); + } + newOrdersGetResponse.setPrice(price); + totalPrice += price; + ordersGetResponses.add(newOrdersGetResponse); + } + + OrdersTodayResponse ordersTodayResponse = new OrdersTodayResponse(); + ordersTodayResponse.setOrdersGetResponses(ordersGetResponses); + ordersTodayResponse.setTotalPrice(totalPrice); + + return ordersTodayResponse; + } + public OrdersDetailResponse getOrderDetails(String userId, Long orderId) { OrdersDetailResponse ordersDetailResponse = new OrdersDetailResponse();