From c0ee6aa11ab6ac32be9c34d56fcbf36c9b74a7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=ED=98=81?= Date: Wed, 20 Nov 2024 19:23:25 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=EC=8B=9D=EA=B6=8C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84=20(#63)=20(?= =?UTF-8?q?#64)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 장바구니 추가 기능 구현 * feat: 장바구니 조회 기능 구현 * feat: 상품 주문과 식권 사용 기능 구현 * style: 포인트트랜잭션 레포지토리명 변경 * deploy: 재배포 * deploy: 재배포2 * deploy: 로그인 로직 수정에 따른 재배포 * deploy: 로그인 로직 수정에 따른 재배포2 * feat: 식권 사용 기능 구현 * feat: yml 수정 사항 반영 --- .../jangburich/domain/order/presentation/OrderController.java | 1 + .../com/jangburich/domain/team/presentation/TeamController.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/jangburich/domain/order/presentation/OrderController.java b/src/main/java/com/jangburich/domain/order/presentation/OrderController.java index d677ec5..8a13196 100644 --- a/src/main/java/com/jangburich/domain/order/presentation/OrderController.java +++ b/src/main/java/com/jangburich/domain/order/presentation/OrderController.java @@ -53,6 +53,7 @@ public ResponseCustom order( } @Operation(summary = "식권 사용", description = "식권을 사용합니다.") + @PostMapping("/tickets") public ResponseCustom useMealTicket( Authentication authentication, @PathVariable Long orderId diff --git a/src/main/java/com/jangburich/domain/team/presentation/TeamController.java b/src/main/java/com/jangburich/domain/team/presentation/TeamController.java index e79ae71..49c9f9b 100644 --- a/src/main/java/com/jangburich/domain/team/presentation/TeamController.java +++ b/src/main/java/com/jangburich/domain/team/presentation/TeamController.java @@ -35,7 +35,7 @@ public ResponseCustom registerTeam( teamService.registerTeam(AuthenticationParser.parseUserId(authentication), registerTeamRequest)); } - @Operation(summary = "팀 가입", description = "비밀 코드를 입력하여, 팀에 가입한다.") + @Operation(summary = "팀 가입", description = "비밀 코드를 입력해 팀에 가입한다.") @PostMapping("/join/{joinCode}") public ResponseCustom joinTeam( Authentication authentication, From 22f902f87029904a1174134fc352c79ebdba00b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=ED=98=81?= Date: Wed, 20 Nov 2024 20:33:01 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20=EC=8B=9D=EA=B6=8C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20(#65)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 장바구니 추가 기능 구현 * feat: 장바구니 조회 기능 구현 * feat: 상품 주문과 식권 사용 기능 구현 * style: 포인트트랜잭션 레포지토리명 변경 * deploy: 재배포 * deploy: 재배포2 * deploy: 로그인 로직 수정에 따른 재배포 * deploy: 로그인 로직 수정에 따른 재배포2 * feat: 식권 사용 기능 구현 * feat: yml 수정 사항 반영 * feat: 식권 사용 로직 수정 --- .../domain/order/application/OrderService.java | 5 ++++- .../jangburich/domain/order/domain/OrderStatus.java | 7 +++++++ .../com/jangburich/domain/order/domain/Orders.java | 13 ++++++++++++- .../domain/order/presentation/OrderController.java | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/jangburich/domain/order/domain/OrderStatus.java diff --git a/src/main/java/com/jangburich/domain/order/application/OrderService.java b/src/main/java/com/jangburich/domain/order/application/OrderService.java index 8e9a5a8..bf59b26 100644 --- a/src/main/java/com/jangburich/domain/order/application/OrderService.java +++ b/src/main/java/com/jangburich/domain/order/application/OrderService.java @@ -5,6 +5,7 @@ import com.jangburich.domain.menu.domain.Menu; import com.jangburich.domain.menu.domain.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; @@ -171,6 +172,7 @@ private Orders saveOrder(User user, Store store, Team team, OrderRequest orderRe .store(store) .user(user) .team(team) + .orderStatus(OrderStatus.RECEIVED) .build(); return ordersRepository.save(orders); } @@ -179,6 +181,7 @@ private void associateCartsWithOrder(List carts, Orders orders) { carts.forEach(cart -> cart.updateOrders(orders)); } + @Transactional public Message useMealTicket(String userProviderId, Long orderId) { User user = userRepository.findByProviderId(userProviderId) .orElseThrow(() -> new NullPointerException()); @@ -188,7 +191,7 @@ public Message useMealTicket(String userProviderId, Long orderId) { orders.validateUser(user); - orders.updateStatus(Status.INACTIVE); + orders.updateOrderStatus(OrderStatus.TICKET_USED); return Message.builder() .message("식권을 사용했습니다.") diff --git a/src/main/java/com/jangburich/domain/order/domain/OrderStatus.java b/src/main/java/com/jangburich/domain/order/domain/OrderStatus.java new file mode 100644 index 0000000..05780ce --- /dev/null +++ b/src/main/java/com/jangburich/domain/order/domain/OrderStatus.java @@ -0,0 +1,7 @@ +package com.jangburich.domain.order.domain; + +public enum OrderStatus { + RECEIVED, // 주문 접수됨, 식권 발급 완료된 상태 + TICKET_USED, // 식권 사용 완료 + CANCELLED // 주문 취소됨 +} diff --git a/src/main/java/com/jangburich/domain/order/domain/Orders.java b/src/main/java/com/jangburich/domain/order/domain/Orders.java index 621f0a9..eef2f73 100644 --- a/src/main/java/com/jangburich/domain/order/domain/Orders.java +++ b/src/main/java/com/jangburich/domain/order/domain/Orders.java @@ -6,6 +6,8 @@ import com.jangburich.domain.user.domain.User; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -39,12 +41,21 @@ public class Orders extends BaseEntity { @JoinColumn(name = "team_id") private Team team; + @Enumerated(EnumType.STRING) + @Column(name = "order_status") + private OrderStatus orderStatus; + @Builder - public Orders(Store store, User user, Team team) { + public Orders(Store store, User user, Team team, OrderStatus orderStatus) { this.store = store; this.user = user; this.team = team; + this.orderStatus = orderStatus; + } + + public void updateOrderStatus(OrderStatus orderStatus) { + this.orderStatus = orderStatus; } public void validateUser(User user) { diff --git a/src/main/java/com/jangburich/domain/order/presentation/OrderController.java b/src/main/java/com/jangburich/domain/order/presentation/OrderController.java index 8a13196..213a6b2 100644 --- a/src/main/java/com/jangburich/domain/order/presentation/OrderController.java +++ b/src/main/java/com/jangburich/domain/order/presentation/OrderController.java @@ -53,7 +53,7 @@ public ResponseCustom order( } @Operation(summary = "식권 사용", description = "식권을 사용합니다.") - @PostMapping("/tickets") + @PostMapping("/tickets/{orderId}") public ResponseCustom useMealTicket( Authentication authentication, @PathVariable Long orderId From 56886e7ec052029a70864a88247cd921d16f4ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=ED=98=81?= Date: Wed, 20 Nov 2024 20:34:07 +0900 Subject: [PATCH 3/9] =?UTF-8?q?feat:=20=EC=8B=9D=EA=B6=8C=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20(#66)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 식권 사용 기능 구현 (#63) * feat: 장바구니 추가 기능 구현 * feat: 장바구니 조회 기능 구현 * feat: 상품 주문과 식권 사용 기능 구현 * style: 포인트트랜잭션 레포지토리명 변경 * deploy: 재배포 * deploy: 재배포2 * deploy: 로그인 로직 수정에 따른 재배포 * deploy: 로그인 로직 수정에 따른 재배포2 * feat: 식권 사용 기능 구현 * feat: yml 수정 사항 반영 * feat: 식권 사용 로직 수정 (#65) * feat: 장바구니 추가 기능 구현 * feat: 장바구니 조회 기능 구현 * feat: 상품 주문과 식권 사용 기능 구현 * style: 포인트트랜잭션 레포지토리명 변경 * deploy: 재배포 * deploy: 재배포2 * deploy: 로그인 로직 수정에 따른 재배포 * deploy: 로그인 로직 수정에 따른 재배포2 * feat: 식권 사용 기능 구현 * feat: yml 수정 사항 반영 * feat: 식권 사용 로직 수정 --- .../domain/order/application/OrderService.java | 5 ++++- .../jangburich/domain/order/domain/OrderStatus.java | 7 +++++++ .../com/jangburich/domain/order/domain/Orders.java | 13 ++++++++++++- .../domain/order/presentation/OrderController.java | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/jangburich/domain/order/domain/OrderStatus.java diff --git a/src/main/java/com/jangburich/domain/order/application/OrderService.java b/src/main/java/com/jangburich/domain/order/application/OrderService.java index 8e9a5a8..bf59b26 100644 --- a/src/main/java/com/jangburich/domain/order/application/OrderService.java +++ b/src/main/java/com/jangburich/domain/order/application/OrderService.java @@ -5,6 +5,7 @@ import com.jangburich.domain.menu.domain.Menu; import com.jangburich.domain.menu.domain.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; @@ -171,6 +172,7 @@ private Orders saveOrder(User user, Store store, Team team, OrderRequest orderRe .store(store) .user(user) .team(team) + .orderStatus(OrderStatus.RECEIVED) .build(); return ordersRepository.save(orders); } @@ -179,6 +181,7 @@ private void associateCartsWithOrder(List carts, Orders orders) { carts.forEach(cart -> cart.updateOrders(orders)); } + @Transactional public Message useMealTicket(String userProviderId, Long orderId) { User user = userRepository.findByProviderId(userProviderId) .orElseThrow(() -> new NullPointerException()); @@ -188,7 +191,7 @@ public Message useMealTicket(String userProviderId, Long orderId) { orders.validateUser(user); - orders.updateStatus(Status.INACTIVE); + orders.updateOrderStatus(OrderStatus.TICKET_USED); return Message.builder() .message("식권을 사용했습니다.") diff --git a/src/main/java/com/jangburich/domain/order/domain/OrderStatus.java b/src/main/java/com/jangburich/domain/order/domain/OrderStatus.java new file mode 100644 index 0000000..05780ce --- /dev/null +++ b/src/main/java/com/jangburich/domain/order/domain/OrderStatus.java @@ -0,0 +1,7 @@ +package com.jangburich.domain.order.domain; + +public enum OrderStatus { + RECEIVED, // 주문 접수됨, 식권 발급 완료된 상태 + TICKET_USED, // 식권 사용 완료 + CANCELLED // 주문 취소됨 +} diff --git a/src/main/java/com/jangburich/domain/order/domain/Orders.java b/src/main/java/com/jangburich/domain/order/domain/Orders.java index 621f0a9..eef2f73 100644 --- a/src/main/java/com/jangburich/domain/order/domain/Orders.java +++ b/src/main/java/com/jangburich/domain/order/domain/Orders.java @@ -6,6 +6,8 @@ import com.jangburich.domain.user.domain.User; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -39,12 +41,21 @@ public class Orders extends BaseEntity { @JoinColumn(name = "team_id") private Team team; + @Enumerated(EnumType.STRING) + @Column(name = "order_status") + private OrderStatus orderStatus; + @Builder - public Orders(Store store, User user, Team team) { + public Orders(Store store, User user, Team team, OrderStatus orderStatus) { this.store = store; this.user = user; this.team = team; + this.orderStatus = orderStatus; + } + + public void updateOrderStatus(OrderStatus orderStatus) { + this.orderStatus = orderStatus; } public void validateUser(User user) { diff --git a/src/main/java/com/jangburich/domain/order/presentation/OrderController.java b/src/main/java/com/jangburich/domain/order/presentation/OrderController.java index 8a13196..213a6b2 100644 --- a/src/main/java/com/jangburich/domain/order/presentation/OrderController.java +++ b/src/main/java/com/jangburich/domain/order/presentation/OrderController.java @@ -53,7 +53,7 @@ public ResponseCustom order( } @Operation(summary = "식권 사용", description = "식권을 사용합니다.") - @PostMapping("/tickets") + @PostMapping("/tickets/{orderId}") public ResponseCustom useMealTicket( Authentication authentication, @PathVariable Long orderId From fbdffb8f49c6976b4059bfd2491a3de769e49c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=ED=98=81?= Date: Wed, 20 Nov 2024 20:50:06 +0900 Subject: [PATCH 4/9] =?UTF-8?q?feat:=20=EC=A3=BC=EB=AC=B8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95=20=EC=99=84=EB=A3=8C=20(#67)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 장바구니 추가 기능 구현 * feat: 장바구니 조회 기능 구현 * feat: 상품 주문과 식권 사용 기능 구현 * style: 포인트트랜잭션 레포지토리명 변경 * deploy: 재배포 * deploy: 재배포2 * deploy: 로그인 로직 수정에 따른 재배포 * deploy: 로그인 로직 수정에 따른 재배포2 * feat: 식권 사용 기능 구현 * feat: yml 수정 사항 반영 * feat: 식권 사용 로직 수정 * feat: 주문 로직 수정 완료 --- .../domain/order/application/OrderService.java | 10 +++++++--- .../domain/order/domain/repository/CartRepository.java | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/jangburich/domain/order/application/OrderService.java b/src/main/java/com/jangburich/domain/order/application/OrderService.java index bf59b26..a2d1994 100644 --- a/src/main/java/com/jangburich/domain/order/application/OrderService.java +++ b/src/main/java/com/jangburich/domain/order/application/OrderService.java @@ -51,7 +51,7 @@ public Message addCart(String userProviderId, AddCartRequest addCartRequest) { System.out.println("menu.getId() = " + menu.getId()); System.out.println("user.getUserId() = " + user.getUserId()); - Optional optionalCart = cartRepository.findByUserIdAndMenuId(user.getUserId(), menu.getId()); + Optional optionalCart = cartRepository.findByUserIdAndMenuIdAndStatus(user.getUserId(), menu.getId(), Status.ACTIVE); Store store = storeRepository.findById(addCartRequest.storeId()) .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 가게 id 입니다.")); @@ -119,7 +119,7 @@ public Message order(String userProviderId, OrderRequest orderRequest) { Team team = teamRepository.findById(orderRequest.teamId()) .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 그룹 id 입니다.")); - List existingCarts = cartRepository.findAllByUserAndStore(user, store); + List existingCarts = cartRepository.findAllByUserAndStoreAndStatus(user, store, Status.ACTIVE); List mergedCarts = mergeCarts(existingCarts, orderRequest.items(), user, store); @@ -136,10 +136,14 @@ public Message order(String userProviderId, OrderRequest orderRequest) { } private List mergeCarts(List existingCarts, List items, User user, Store store) { + List orderedMenuIds = items.stream() + .map(OrderRequest.OrderItemRequest::menuId) + .toList(); + for (OrderRequest.OrderItemRequest item : items) { Optional existingCart = findCartByMenuId(existingCarts, item.menuId()); if (existingCart.isPresent()) { - existingCart.get().updateQuantity(existingCart.get().getQuantity() + item.quantity()); + existingCart.get().updateQuantity(item.quantity()); existingCart.get().updateStatus(Status.INACTIVE); continue; } diff --git a/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java b/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java index a21d4e7..12083d2 100644 --- a/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java +++ b/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java @@ -13,10 +13,10 @@ @Repository public interface CartRepository extends JpaRepository { - @Query("SELECT c FROM Cart c WHERE c.user.userId = :userId AND c.menu.id = :menuId") - Optional findByUserIdAndMenuId(@Param("userId") Long userId, @Param("menuId") Long menuId); - - List findAllByUserAndStore(User user, Store store); + @Query("SELECT c FROM Cart c WHERE c.user.userId = :userId AND c.menu.id = :menuId AND c.status = :status") + Optional findByUserIdAndMenuIdAndStatus(@Param("userId") Long userId, @Param("menuId") Long menuId, @Param("status") Status status); List findAllByUserAndStatus(User user, Status status); + + List findAllByUserAndStoreAndStatus(User user, Store store, Status status); } From d4c8f363c3b07a15b0c693ba199ce59ecd793122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=ED=98=81?= Date: Wed, 20 Nov 2024 20:50:30 +0900 Subject: [PATCH 5/9] =?UTF-8?q?feat:=20=EC=A3=BC=EB=AC=B8=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95=20=EC=99=84=EB=A3=8C=20(#68)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 식권 사용 기능 구현 (#63) * feat: 장바구니 추가 기능 구현 * feat: 장바구니 조회 기능 구현 * feat: 상품 주문과 식권 사용 기능 구현 * style: 포인트트랜잭션 레포지토리명 변경 * deploy: 재배포 * deploy: 재배포2 * deploy: 로그인 로직 수정에 따른 재배포 * deploy: 로그인 로직 수정에 따른 재배포2 * feat: 식권 사용 기능 구현 * feat: yml 수정 사항 반영 * feat: 식권 사용 로직 수정 (#65) * feat: 장바구니 추가 기능 구현 * feat: 장바구니 조회 기능 구현 * feat: 상품 주문과 식권 사용 기능 구현 * style: 포인트트랜잭션 레포지토리명 변경 * deploy: 재배포 * deploy: 재배포2 * deploy: 로그인 로직 수정에 따른 재배포 * deploy: 로그인 로직 수정에 따른 재배포2 * feat: 식권 사용 기능 구현 * feat: yml 수정 사항 반영 * feat: 식권 사용 로직 수정 * feat: 주문 로직 수정 완료 (#67) * feat: 장바구니 추가 기능 구현 * feat: 장바구니 조회 기능 구현 * feat: 상품 주문과 식권 사용 기능 구현 * style: 포인트트랜잭션 레포지토리명 변경 * deploy: 재배포 * deploy: 재배포2 * deploy: 로그인 로직 수정에 따른 재배포 * deploy: 로그인 로직 수정에 따른 재배포2 * feat: 식권 사용 기능 구현 * feat: yml 수정 사항 반영 * feat: 식권 사용 로직 수정 * feat: 주문 로직 수정 완료 --- .../domain/order/application/OrderService.java | 10 +++++++--- .../domain/order/domain/repository/CartRepository.java | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/jangburich/domain/order/application/OrderService.java b/src/main/java/com/jangburich/domain/order/application/OrderService.java index bf59b26..a2d1994 100644 --- a/src/main/java/com/jangburich/domain/order/application/OrderService.java +++ b/src/main/java/com/jangburich/domain/order/application/OrderService.java @@ -51,7 +51,7 @@ public Message addCart(String userProviderId, AddCartRequest addCartRequest) { System.out.println("menu.getId() = " + menu.getId()); System.out.println("user.getUserId() = " + user.getUserId()); - Optional optionalCart = cartRepository.findByUserIdAndMenuId(user.getUserId(), menu.getId()); + Optional optionalCart = cartRepository.findByUserIdAndMenuIdAndStatus(user.getUserId(), menu.getId(), Status.ACTIVE); Store store = storeRepository.findById(addCartRequest.storeId()) .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 가게 id 입니다.")); @@ -119,7 +119,7 @@ public Message order(String userProviderId, OrderRequest orderRequest) { Team team = teamRepository.findById(orderRequest.teamId()) .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 그룹 id 입니다.")); - List existingCarts = cartRepository.findAllByUserAndStore(user, store); + List existingCarts = cartRepository.findAllByUserAndStoreAndStatus(user, store, Status.ACTIVE); List mergedCarts = mergeCarts(existingCarts, orderRequest.items(), user, store); @@ -136,10 +136,14 @@ public Message order(String userProviderId, OrderRequest orderRequest) { } private List mergeCarts(List existingCarts, List items, User user, Store store) { + List orderedMenuIds = items.stream() + .map(OrderRequest.OrderItemRequest::menuId) + .toList(); + for (OrderRequest.OrderItemRequest item : items) { Optional existingCart = findCartByMenuId(existingCarts, item.menuId()); if (existingCart.isPresent()) { - existingCart.get().updateQuantity(existingCart.get().getQuantity() + item.quantity()); + existingCart.get().updateQuantity(item.quantity()); existingCart.get().updateStatus(Status.INACTIVE); continue; } diff --git a/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java b/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java index a21d4e7..12083d2 100644 --- a/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java +++ b/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java @@ -13,10 +13,10 @@ @Repository public interface CartRepository extends JpaRepository { - @Query("SELECT c FROM Cart c WHERE c.user.userId = :userId AND c.menu.id = :menuId") - Optional findByUserIdAndMenuId(@Param("userId") Long userId, @Param("menuId") Long menuId); - - List findAllByUserAndStore(User user, Store store); + @Query("SELECT c FROM Cart c WHERE c.user.userId = :userId AND c.menu.id = :menuId AND c.status = :status") + Optional findByUserIdAndMenuIdAndStatus(@Param("userId") Long userId, @Param("menuId") Long menuId, @Param("status") Status status); List findAllByUserAndStatus(User user, Status status); + + List findAllByUserAndStoreAndStatus(User user, Store store, Status status); } From 07c8184e12a74dd11ef8579b7587069390143bd6 Mon Sep 17 00:00:00 2001 From: HyunWoo9930 Date: Wed, 20 Nov 2024 22:30:46 +0900 Subject: [PATCH 6/9] =?UTF-8?q?fix=20:=20menu=20page=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=20=EB=B0=98=ED=99=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MenuController.java | 14 +++++++----- .../domain/menu/domain/MenuResponse.java | 22 +++++++++++++++++++ .../domain/repository/MenuRepository.java | 12 ---------- .../menu/repository/MenuRepository.java | 13 +++++++++++ .../{domain => }/service/MenuService.java | 15 ++++++------- .../order/application/OrderService.java | 2 +- .../store/domain/service/StoreService.java | 2 +- 7 files changed, 52 insertions(+), 28 deletions(-) rename src/main/java/com/jangburich/domain/menu/{domain => }/controller/MenuController.java (82%) create mode 100644 src/main/java/com/jangburich/domain/menu/domain/MenuResponse.java delete mode 100644 src/main/java/com/jangburich/domain/menu/domain/repository/MenuRepository.java create mode 100644 src/main/java/com/jangburich/domain/menu/repository/MenuRepository.java rename src/main/java/com/jangburich/domain/menu/{domain => }/service/MenuService.java (89%) diff --git a/src/main/java/com/jangburich/domain/menu/domain/controller/MenuController.java b/src/main/java/com/jangburich/domain/menu/controller/MenuController.java similarity index 82% rename from src/main/java/com/jangburich/domain/menu/domain/controller/MenuController.java rename to src/main/java/com/jangburich/domain/menu/controller/MenuController.java index 6a2fd03..dfeffd3 100644 --- a/src/main/java/com/jangburich/domain/menu/domain/controller/MenuController.java +++ b/src/main/java/com/jangburich/domain/menu/controller/MenuController.java @@ -1,22 +1,24 @@ -package com.jangburich.domain.menu.domain.controller; +package com.jangburich.domain.menu.controller; import java.util.List; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.jangburich.domain.menu.domain.MenuCreateRequestDTO; import com.jangburich.domain.menu.domain.MenuGetResponseDTO; +import com.jangburich.domain.menu.domain.MenuResponse; import com.jangburich.domain.menu.domain.MenuUpdateRequestDTO; -import com.jangburich.domain.menu.domain.service.MenuService; +import com.jangburich.domain.menu.service.MenuService; import com.jangburich.global.payload.Message; import com.jangburich.global.payload.ResponseCustom; import com.jangburich.utils.parser.AuthenticationParser; @@ -56,9 +58,9 @@ public ResponseCustom deleteMenu( } @GetMapping("") - public ResponseCustom> getMenu( - Authentication authentication) { - List menu = menuService.getMenu(AuthenticationParser.parseUserId(authentication)); + public ResponseCustom> getMenu( + Authentication authentication, Pageable pageable) { + Page menu = menuService.getMenu(AuthenticationParser.parseUserId(authentication), pageable); return ResponseCustom.OK(menu); } } diff --git a/src/main/java/com/jangburich/domain/menu/domain/MenuResponse.java b/src/main/java/com/jangburich/domain/menu/domain/MenuResponse.java new file mode 100644 index 0000000..4156cff --- /dev/null +++ b/src/main/java/com/jangburich/domain/menu/domain/MenuResponse.java @@ -0,0 +1,22 @@ +package com.jangburich.domain.menu.domain; + +import com.querydsl.core.annotations.QueryProjection; + +public record MenuResponse( + Long id, + Long storeId, + String name, + String description, + String imageUrl, + Integer price +) { + @QueryProjection + public MenuResponse(Long id, Long storeId, String name, String description, String imageUrl, Integer price) { + this.id = id; + this.storeId = storeId; + this.name = name; + this.description = description; + this.imageUrl = imageUrl; + this.price = price; + } +} diff --git a/src/main/java/com/jangburich/domain/menu/domain/repository/MenuRepository.java b/src/main/java/com/jangburich/domain/menu/domain/repository/MenuRepository.java deleted file mode 100644 index 7185e92..0000000 --- a/src/main/java/com/jangburich/domain/menu/domain/repository/MenuRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.jangburich.domain.menu.domain.repository; - -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.jangburich.domain.menu.domain.Menu; -import com.jangburich.domain.store.domain.Store; - -public interface MenuRepository extends JpaRepository { - List findAllByStore(Store store); -} diff --git a/src/main/java/com/jangburich/domain/menu/repository/MenuRepository.java b/src/main/java/com/jangburich/domain/menu/repository/MenuRepository.java new file mode 100644 index 0000000..53c21f1 --- /dev/null +++ b/src/main/java/com/jangburich/domain/menu/repository/MenuRepository.java @@ -0,0 +1,13 @@ +package com.jangburich.domain.menu.repository; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +import com.jangburich.domain.menu.domain.Menu; +import com.jangburich.domain.menu.domain.MenuResponse; +import com.jangburich.domain.store.domain.Store; + +public interface MenuRepository extends JpaRepository { + Page findAllByStore(Store store, Pageable pageable); +} diff --git a/src/main/java/com/jangburich/domain/menu/domain/service/MenuService.java b/src/main/java/com/jangburich/domain/menu/service/MenuService.java similarity index 89% rename from src/main/java/com/jangburich/domain/menu/domain/service/MenuService.java rename to src/main/java/com/jangburich/domain/menu/service/MenuService.java index da07a52..62da9dc 100644 --- a/src/main/java/com/jangburich/domain/menu/domain/service/MenuService.java +++ b/src/main/java/com/jangburich/domain/menu/service/MenuService.java @@ -1,15 +1,18 @@ -package com.jangburich.domain.menu.domain.service; +package com.jangburich.domain.menu.service; import java.util.List; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.jangburich.domain.menu.domain.Menu; import com.jangburich.domain.menu.domain.MenuCreateRequestDTO; import com.jangburich.domain.menu.domain.MenuGetResponseDTO; +import com.jangburich.domain.menu.domain.MenuResponse; import com.jangburich.domain.menu.domain.MenuUpdateRequestDTO; -import com.jangburich.domain.menu.domain.repository.MenuRepository; +import com.jangburich.domain.menu.repository.MenuRepository; import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; import com.jangburich.domain.store.domain.Store; @@ -72,7 +75,7 @@ public void deleteMenu(String customOAuthUser, Long id) { menuRepository.delete(menu); } - public List getMenu(String customOAuthUser) { + public Page getMenu(String customOAuthUser, Pageable pageable) { User user = userRepository.findByProviderId(customOAuthUser) .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); @@ -82,10 +85,6 @@ public List getMenu(String customOAuthUser) { Store store = storeRepository.findByOwner(owner) .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_STORE_ID)); - return menuRepository.findAllByStore(store) - .stream() - .map(menu -> new MenuGetResponseDTO(menu.getId(), menu.getName(), menu.getDescription(), menu.getImageUrl(), - menu.getPrice(), menu.getStore().getId())) - .toList(); + return menuRepository.findAllByStore(store,pageable); } } diff --git a/src/main/java/com/jangburich/domain/order/application/OrderService.java b/src/main/java/com/jangburich/domain/order/application/OrderService.java index a2d1994..ecc4f4b 100644 --- a/src/main/java/com/jangburich/domain/order/application/OrderService.java +++ b/src/main/java/com/jangburich/domain/order/application/OrderService.java @@ -3,7 +3,7 @@ import com.amazonaws.services.kms.model.NotFoundException; import com.jangburich.domain.common.Status; import com.jangburich.domain.menu.domain.Menu; -import com.jangburich.domain.menu.domain.repository.MenuRepository; +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; diff --git a/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java b/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java index 561a452..3849c08 100644 --- a/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java +++ b/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java @@ -8,7 +8,7 @@ import com.jangburich.domain.menu.domain.Menu; import com.jangburich.domain.menu.domain.MenuCreateRequestDTO; -import com.jangburich.domain.menu.domain.repository.MenuRepository; +import com.jangburich.domain.menu.repository.MenuRepository; import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; import com.jangburich.domain.payment.domain.TeamChargeHistoryResponse; From 0f73d2e66c34cdc68fbe0a2b42a5b2cf15db5e72 Mon Sep 17 00:00:00 2001 From: HyunWoo9930 Date: Wed, 20 Nov 2024 23:21:57 +0900 Subject: [PATCH 7/9] =?UTF-8?q?feat=20:=20=EC=A7=80=EB=82=9C=20=EC=A3=BC?= =?UTF-8?q?=EB=AC=B8=20=EC=A1=B0=ED=9A=8C=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/menu/service/MenuService.java | 5 +- .../order/application/OrderService.java | 4 +- .../domain/repository/CartRepository.java | 3 + .../domain/repository/OrdersRepository.java | 17 ++++++ .../payment/application/KakaopayService.java | 4 +- .../controller/StoreController.java | 48 ++++++++------- .../dto/condition/StoreSearchCondition.java | 2 +- .../StoreSearchConditionWithType.java | 2 +- .../store/dto/response/OrdersGetResponse.java | 18 ++++++ .../response/PaymentGroupDetailResponse.java | 2 +- .../dto/response/SearchStoresResponse.java | 2 +- .../repository/StoreQueryDslRepository.java | 8 +-- .../StoreQueryDslRepositoryImpl.java | 10 ++-- .../repository/StoreRepository.java | 2 +- .../repository/StoreTeamRepository.java | 2 +- .../{domain => }/service/StoreService.java | 60 ++++++++++++++++--- .../domain/user/service/UserService.java | 2 +- 17 files changed, 137 insertions(+), 54 deletions(-) rename src/main/java/com/jangburich/domain/store/{domain => }/controller/StoreController.java (78%) rename src/main/java/com/jangburich/domain/store/{domain => }/dto/condition/StoreSearchCondition.java (58%) rename src/main/java/com/jangburich/domain/store/{domain => }/dto/condition/StoreSearchConditionWithType.java (90%) create mode 100644 src/main/java/com/jangburich/domain/store/dto/response/OrdersGetResponse.java rename src/main/java/com/jangburich/domain/store/{domain => }/dto/response/PaymentGroupDetailResponse.java (95%) rename src/main/java/com/jangburich/domain/store/{domain => }/dto/response/SearchStoresResponse.java (94%) rename src/main/java/com/jangburich/domain/store/{domain => }/repository/StoreQueryDslRepository.java (63%) rename src/main/java/com/jangburich/domain/store/{domain => }/repository/StoreQueryDslRepositoryImpl.java (93%) rename src/main/java/com/jangburich/domain/store/{domain => }/repository/StoreRepository.java (87%) rename src/main/java/com/jangburich/domain/store/{domain => }/repository/StoreTeamRepository.java (91%) rename src/main/java/com/jangburich/domain/store/{domain => }/service/StoreService.java (81%) diff --git a/src/main/java/com/jangburich/domain/menu/service/MenuService.java b/src/main/java/com/jangburich/domain/menu/service/MenuService.java index 62da9dc..efc8b28 100644 --- a/src/main/java/com/jangburich/domain/menu/service/MenuService.java +++ b/src/main/java/com/jangburich/domain/menu/service/MenuService.java @@ -1,7 +1,5 @@ package com.jangburich.domain.menu.service; -import java.util.List; - import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -9,14 +7,13 @@ import com.jangburich.domain.menu.domain.Menu; import com.jangburich.domain.menu.domain.MenuCreateRequestDTO; -import com.jangburich.domain.menu.domain.MenuGetResponseDTO; import com.jangburich.domain.menu.domain.MenuResponse; import com.jangburich.domain.menu.domain.MenuUpdateRequestDTO; import com.jangburich.domain.menu.repository.MenuRepository; import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; import com.jangburich.domain.store.domain.Store; -import com.jangburich.domain.store.domain.repository.StoreRepository; +import com.jangburich.domain.store.repository.StoreRepository; import com.jangburich.domain.user.domain.User; import com.jangburich.domain.user.repository.UserRepository; import com.jangburich.global.error.DefaultNullPointerException; diff --git a/src/main/java/com/jangburich/domain/order/application/OrderService.java b/src/main/java/com/jangburich/domain/order/application/OrderService.java index ecc4f4b..0b2ec5b 100644 --- a/src/main/java/com/jangburich/domain/order/application/OrderService.java +++ b/src/main/java/com/jangburich/domain/order/application/OrderService.java @@ -14,8 +14,8 @@ import com.jangburich.domain.order.dto.response.CartResponse; import com.jangburich.domain.order.dto.response.GetCartItemsResponse; import com.jangburich.domain.store.domain.Store; -import com.jangburich.domain.store.domain.repository.StoreRepository; -import com.jangburich.domain.store.domain.repository.StoreTeamRepository; +import com.jangburich.domain.store.repository.StoreRepository; +import com.jangburich.domain.store.repository.StoreTeamRepository; import com.jangburich.domain.team.domain.Team; import com.jangburich.domain.team.domain.repository.TeamRepository; import com.jangburich.domain.user.domain.User; diff --git a/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java b/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java index 12083d2..1120175 100644 --- a/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java +++ b/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java @@ -2,6 +2,7 @@ import com.jangburich.domain.common.Status; import com.jangburich.domain.order.domain.Cart; +import com.jangburich.domain.order.domain.Orders; import com.jangburich.domain.store.domain.Store; import com.jangburich.domain.user.domain.User; import java.util.List; @@ -19,4 +20,6 @@ public interface CartRepository extends JpaRepository { List findAllByUserAndStatus(User user, Status status); List findAllByUserAndStoreAndStatus(User user, Store store, Status status); + + List findAllByOrders(Orders orders); } 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 b1e47b8..23097c9 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 @@ -1,9 +1,26 @@ package com.jangburich.domain.order.domain.repository; +import java.time.LocalDateTime; +import java.util.List; + +import com.jangburich.domain.order.domain.OrderStatus; import com.jangburich.domain.order.domain.Orders; +import com.jangburich.domain.store.domain.Store; + +import org.aspectj.weaver.ast.Or; +import org.hibernate.query.Order; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @Repository public interface OrdersRepository extends JpaRepository { + @Query(value = "SELECT * FROM orders WHERE store_id = :storeId AND updated_at < :updatedAt AND order_status = :orderStatus", + nativeQuery = true) + List findOrdersByStoreAndDateAndStatusNative( + @Param("storeId") Long storeId, + @Param("updatedAt") LocalDateTime updatedAt, + @Param("orderStatus") String orderStatus); + } diff --git a/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java b/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java index 4f47145..4a153e6 100644 --- a/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java +++ b/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java @@ -20,8 +20,8 @@ import com.jangburich.domain.payment.exception.TeamNotFoundException; import com.jangburich.domain.store.domain.Store; import com.jangburich.domain.store.domain.StoreTeam; -import com.jangburich.domain.store.domain.repository.StoreRepository; -import com.jangburich.domain.store.domain.repository.StoreTeamRepository; +import com.jangburich.domain.store.repository.StoreRepository; +import com.jangburich.domain.store.repository.StoreTeamRepository; import com.jangburich.domain.store.exception.StoreNotFoundException; import com.jangburich.domain.team.domain.Team; import com.jangburich.domain.team.domain.repository.TeamRepository; diff --git a/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java b/src/main/java/com/jangburich/domain/store/controller/StoreController.java similarity index 78% rename from src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java rename to src/main/java/com/jangburich/domain/store/controller/StoreController.java index b25685f..23572db 100644 --- a/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java +++ b/src/main/java/com/jangburich/domain/store/controller/StoreController.java @@ -1,4 +1,6 @@ -package com.jangburich.domain.store.domain.controller; +package com.jangburich.domain.store.controller; + +import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -22,11 +24,12 @@ import com.jangburich.domain.store.domain.StoreGetResponseDTO; import com.jangburich.domain.store.domain.StoreTeamResponseDTO; import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; -import com.jangburich.domain.store.domain.dto.response.PaymentGroupDetailResponse; -import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; -import com.jangburich.domain.store.domain.service.StoreService; +import com.jangburich.domain.store.dto.condition.StoreSearchCondition; +import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.dto.response.OrdersGetResponse; +import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse; +import com.jangburich.domain.store.dto.response.SearchStoresResponse; +import com.jangburich.domain.store.service.StoreService; import com.jangburich.global.payload.Message; import com.jangburich.global.payload.ResponseCustom; import com.jangburich.utils.parser.AuthenticationParser; @@ -67,21 +70,17 @@ public ResponseCustom> searchStores( @Operation(summary = "가게 등록", description = "신규 파트너 가게를 등록합니다.") @PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public ResponseCustom createStore( - Authentication authentication, - @Parameter(name = "image", description = "업로드 사진 데이터") - @RequestPart(value = "image") MultipartFile image, + public ResponseCustom createStore(Authentication authentication, + @Parameter(name = "image", description = "업로드 사진 데이터") @RequestPart(value = "image") MultipartFile image, @RequestPart(value = "store") StoreCreateRequestDTO storeCreateRequestDTO) { storeService.createStore(AuthenticationParser.parseUserId(authentication), storeCreateRequestDTO, image); return ResponseCustom.OK(Message.builder().message("success").build()); } - @Operation(summary = "가게 정보 수정", description = "가게 정보를 수정합니다.") @PatchMapping("/update") - public ResponseCustom updateStore( - Authentication authentication, + public ResponseCustom updateStore(Authentication authentication, @RequestBody StoreUpdateRequestDTO storeUpdateRequestDTO) { storeService.updateStore(AuthenticationParser.parseUserId(authentication), storeUpdateRequestDTO); return ResponseCustom.OK(Message.builder().message("success").build()); @@ -89,15 +88,13 @@ public ResponseCustom updateStore( @Operation(summary = "가게 정보 조회", description = "가게 상세 정보를 조회합니다.") @GetMapping("") - public ResponseCustom getStoreInfo( - Authentication authentication) { + public ResponseCustom getStoreInfo(Authentication authentication) { return ResponseCustom.OK(storeService.getStoreInfo(AuthenticationParser.parseUserId(authentication))); } @Operation(summary = "결제 그룹 조회", description = "장부 결제 그룹을 조회합니다.") @GetMapping("/payment_group") - public ResponseCustom> getPaymentGroup( - Authentication authentication, + public ResponseCustom> getPaymentGroup(Authentication authentication, Pageable pageable) { return ResponseCustom.OK( storeService.getPaymentGroup(AuthenticationParser.parseUserId(authentication), pageable)); @@ -105,19 +102,24 @@ public ResponseCustom> getPaymentGroup( @Operation(summary = "결제 그룹 상세 조회", description = "장부 결제 그룹을 상세 조회합니다.") @GetMapping("/payment_group/{teamId}") - public ResponseCustom getPaymentGroupDetail( - Authentication authentication, @PathVariable Long teamId, - Pageable pageable) { + public ResponseCustom getPaymentGroupDetail(Authentication authentication, + @PathVariable Long teamId, Pageable pageable) { return ResponseCustom.OK( storeService.getPaymentGroupDetail(AuthenticationParser.parseUserId(authentication), teamId, pageable)); } @Operation(summary = "결제 내역 조회", description = "가게에서 일어난 결제 내역을 조회합니다.") @GetMapping("/payment_history") - public ResponseCustom getPaymentHistory( - Authentication authentication, - Pageable pageable) { + public ResponseCustom getPaymentHistory(Authentication authentication, Pageable pageable) { return ResponseCustom.OK( storeService.getPaymentHistory(AuthenticationParser.parseUserId(authentication), pageable)); } + + @Operation(summary = "지난 주문 조회", description = "가게에 있는 지난 주문을 조회합니다") + @GetMapping("/orders/last") + public ResponseCustom> getOrders(Authentication authentication) { + List ordersLast = storeService.getOrdersLast( + AuthenticationParser.parseUserId(authentication)); + return ResponseCustom.OK(ordersLast); + } } \ No newline at end of file diff --git a/src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchCondition.java b/src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchCondition.java similarity index 58% rename from src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchCondition.java rename to src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchCondition.java index 96249c4..9b5d309 100644 --- a/src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchCondition.java +++ b/src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchCondition.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.dto.condition; +package com.jangburich.domain.store.dto.condition; public record StoreSearchCondition( Double lat, diff --git a/src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchConditionWithType.java b/src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchConditionWithType.java similarity index 90% rename from src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchConditionWithType.java rename to src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchConditionWithType.java index d807d6c..092d941 100644 --- a/src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchConditionWithType.java +++ b/src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchConditionWithType.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.dto.condition; +package com.jangburich.domain.store.dto.condition; import com.querydsl.core.annotations.QueryProjection; diff --git a/src/main/java/com/jangburich/domain/store/dto/response/OrdersGetResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/OrdersGetResponse.java new file mode 100644 index 0000000..3582ba3 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/dto/response/OrdersGetResponse.java @@ -0,0 +1,18 @@ +package com.jangburich.domain.store.dto.response; + +import java.time.LocalDateTime; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class OrdersGetResponse { + private Long id; + private String menuNames; + private LocalDateTime date; + private Integer count; + private Integer price; +} diff --git a/src/main/java/com/jangburich/domain/store/domain/dto/response/PaymentGroupDetailResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/PaymentGroupDetailResponse.java similarity index 95% rename from src/main/java/com/jangburich/domain/store/domain/dto/response/PaymentGroupDetailResponse.java rename to src/main/java/com/jangburich/domain/store/dto/response/PaymentGroupDetailResponse.java index 20bdd5d..ef096a6 100644 --- a/src/main/java/com/jangburich/domain/store/domain/dto/response/PaymentGroupDetailResponse.java +++ b/src/main/java/com/jangburich/domain/store/dto/response/PaymentGroupDetailResponse.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.dto.response; +package com.jangburich.domain.store.dto.response; import org.springframework.data.domain.Page; diff --git a/src/main/java/com/jangburich/domain/store/domain/dto/response/SearchStoresResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/SearchStoresResponse.java similarity index 94% rename from src/main/java/com/jangburich/domain/store/domain/dto/response/SearchStoresResponse.java rename to src/main/java/com/jangburich/domain/store/dto/response/SearchStoresResponse.java index 3036c13..3aea72d 100644 --- a/src/main/java/com/jangburich/domain/store/domain/dto/response/SearchStoresResponse.java +++ b/src/main/java/com/jangburich/domain/store/dto/response/SearchStoresResponse.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.dto.response; +package com.jangburich.domain.store.dto.response; import com.jangburich.domain.store.domain.Category; import com.querydsl.core.annotations.QueryProjection; diff --git a/src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepository.java b/src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepository.java similarity index 63% rename from src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepository.java rename to src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepository.java index d2e618d..5edbea3 100644 --- a/src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepository.java +++ b/src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepository.java @@ -1,9 +1,9 @@ -package com.jangburich.domain.store.domain.repository; +package com.jangburich.domain.store.repository; import com.jangburich.domain.store.domain.Category; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; -import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; +import com.jangburich.domain.store.dto.condition.StoreSearchCondition; +import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.dto.response.SearchStoresResponse; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepositoryImpl.java b/src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepositoryImpl.java similarity index 93% rename from src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepositoryImpl.java rename to src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepositoryImpl.java index 03f15e6..7e88bef 100644 --- a/src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepositoryImpl.java +++ b/src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepositoryImpl.java @@ -1,12 +1,12 @@ -package com.jangburich.domain.store.domain.repository; +package com.jangburich.domain.store.repository; import static com.jangburich.domain.store.domain.QStore.store; import com.jangburich.domain.store.domain.Category; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; -import com.jangburich.domain.store.domain.dto.response.QSearchStoresResponse; -import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; +import com.jangburich.domain.store.dto.condition.StoreSearchCondition; +import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.dto.response.QSearchStoresResponse; +import com.jangburich.domain.store.dto.response.SearchStoresResponse; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.core.types.dsl.Expressions; import com.querydsl.jpa.impl.JPAQuery; diff --git a/src/main/java/com/jangburich/domain/store/domain/repository/StoreRepository.java b/src/main/java/com/jangburich/domain/store/repository/StoreRepository.java similarity index 87% rename from src/main/java/com/jangburich/domain/store/domain/repository/StoreRepository.java rename to src/main/java/com/jangburich/domain/store/repository/StoreRepository.java index 7525f86..a6b549c 100644 --- a/src/main/java/com/jangburich/domain/store/domain/repository/StoreRepository.java +++ b/src/main/java/com/jangburich/domain/store/repository/StoreRepository.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.repository; +package com.jangburich.domain.store.repository; import java.util.Optional; diff --git a/src/main/java/com/jangburich/domain/store/domain/repository/StoreTeamRepository.java b/src/main/java/com/jangburich/domain/store/repository/StoreTeamRepository.java similarity index 91% rename from src/main/java/com/jangburich/domain/store/domain/repository/StoreTeamRepository.java rename to src/main/java/com/jangburich/domain/store/repository/StoreTeamRepository.java index e05e178..2fa84fb 100644 --- a/src/main/java/com/jangburich/domain/store/domain/repository/StoreTeamRepository.java +++ b/src/main/java/com/jangburich/domain/store/repository/StoreTeamRepository.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.repository; +package com.jangburich.domain.store.repository; import java.util.Optional; diff --git a/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java b/src/main/java/com/jangburich/domain/store/service/StoreService.java similarity index 81% rename from src/main/java/com/jangburich/domain/store/domain/service/StoreService.java rename to src/main/java/com/jangburich/domain/store/service/StoreService.java index 3849c08..b688145 100644 --- a/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java +++ b/src/main/java/com/jangburich/domain/store/service/StoreService.java @@ -1,4 +1,9 @@ -package com.jangburich.domain.store.domain.service; +package com.jangburich.domain.store.service; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -9,6 +14,10 @@ import com.jangburich.domain.menu.domain.Menu; 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.Orders; +import com.jangburich.domain.order.domain.repository.CartRepository; +import com.jangburich.domain.order.domain.repository.OrdersRepository; import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; import com.jangburich.domain.payment.domain.TeamChargeHistoryResponse; @@ -22,12 +31,13 @@ import com.jangburich.domain.store.domain.StoreTeam; import com.jangburich.domain.store.domain.StoreTeamResponseDTO; import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; -import com.jangburich.domain.store.domain.dto.response.PaymentGroupDetailResponse; -import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; -import com.jangburich.domain.store.domain.repository.StoreRepository; -import com.jangburich.domain.store.domain.repository.StoreTeamRepository; +import com.jangburich.domain.store.dto.condition.StoreSearchCondition; +import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.dto.response.OrdersGetResponse; +import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse; +import com.jangburich.domain.store.dto.response.SearchStoresResponse; +import com.jangburich.domain.store.repository.StoreRepository; +import com.jangburich.domain.store.repository.StoreTeamRepository; import com.jangburich.domain.team.domain.Team; import com.jangburich.domain.team.domain.repository.TeamRepository; import com.jangburich.domain.user.domain.User; @@ -50,6 +60,8 @@ public class StoreService { private final TeamChargeHistoryRepository teamChargeHistoryRepository; private final MenuRepository menuRepository; private final S3Service s3Service; + private final OrdersRepository ordersRepository; + private final CartRepository cartRepository; @Transactional public void createStore(String authentication, StoreCreateRequestDTO storeCreateRequestDTO, MultipartFile image) { @@ -238,4 +250,38 @@ public Page getPaymentHistory(String userId, Pageabl Page historyResponses = teamChargeHistoryRepository.findAllByStore(store, pageable); return historyResponses; } + + public List getOrdersLast(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 todayStart = LocalDate.now().atStartOfDay(); + List allByStore = ordersRepository.findOrdersByStoreAndDateAndStatusNative(store.getId(), todayStart, + "TICKET_USED"); + + 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()); + Integer price = 0; + for (Cart cart : carts) { + price += cart.getMenu().getPrice(); + } + newOrdersGetResponse.setPrice(price); + ordersGetResponses.add(newOrdersGetResponse); + } + + return ordersGetResponses; + } } diff --git a/src/main/java/com/jangburich/domain/user/service/UserService.java b/src/main/java/com/jangburich/domain/user/service/UserService.java index 6259e6f..b67b7dd 100644 --- a/src/main/java/com/jangburich/domain/user/service/UserService.java +++ b/src/main/java/com/jangburich/domain/user/service/UserService.java @@ -12,7 +12,7 @@ import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; import com.jangburich.domain.store.domain.Store; -import com.jangburich.domain.store.domain.repository.StoreRepository; +import com.jangburich.domain.store.repository.StoreRepository; import com.jangburich.domain.user.domain.AdditionalInfoCreateDTO; import com.jangburich.domain.user.domain.KakaoApiResponseDTO; import com.jangburich.domain.user.domain.TokenResponseDTO; From 5f0e23cada737bb034c616b11d681fcfe2a1c331 Mon Sep 17 00:00:00 2001 From: HyunWoo9930 Date: Wed, 20 Nov 2024 23:40:18 +0900 Subject: [PATCH 8/9] =?UTF-8?q?feat=20:=20=EC=A3=BC=EB=AC=B8=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20api=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/controller/StoreController.java | 9 +++++ .../dto/response/OrdersDetailResponse.java | 30 ++++++++++++++ .../exception/OrdersNotFoundException.java | 7 ++++ .../domain/store/service/StoreService.java | 40 ++++++++++++++++++- 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/jangburich/domain/store/dto/response/OrdersDetailResponse.java create mode 100644 src/main/java/com/jangburich/domain/store/exception/OrdersNotFoundException.java 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 23572db..7bbd9c2 100644 --- a/src/main/java/com/jangburich/domain/store/controller/StoreController.java +++ b/src/main/java/com/jangburich/domain/store/controller/StoreController.java @@ -26,6 +26,7 @@ import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; import com.jangburich.domain.store.dto.condition.StoreSearchCondition; 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.PaymentGroupDetailResponse; import com.jangburich.domain.store.dto.response.SearchStoresResponse; @@ -122,4 +123,12 @@ public ResponseCustom> getOrders(Authentication authenti AuthenticationParser.parseUserId(authentication)); return ResponseCustom.OK(ordersLast); } + + @Operation(summary = "주문 상세 조회", description = "가게에 있는 주문을 상세 조회합니다") + @GetMapping("/orders/{ordersId}") + public ResponseCustom getOrders(Authentication authentication, @RequestParam Long orderId) { + return ResponseCustom.OK( + storeService.getOrderDetails(AuthenticationParser.parseUserId(authentication), orderId)); + } + } \ No newline at end of file diff --git a/src/main/java/com/jangburich/domain/store/dto/response/OrdersDetailResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/OrdersDetailResponse.java new file mode 100644 index 0000000..73b5c28 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/dto/response/OrdersDetailResponse.java @@ -0,0 +1,30 @@ +package com.jangburich.domain.store.dto.response; + +import java.time.LocalDateTime; +import java.util.List; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class OrdersDetailResponse { + private Long id; + private String teamName; + private String teamUserName; + private List menus; + private LocalDateTime dateTime; + private Integer amount; + private Integer totalPrice; + private Integer discountPrice; + + @Getter + @Setter + public static class Menu { + private String menuName; + private Integer amount; + } +} + diff --git a/src/main/java/com/jangburich/domain/store/exception/OrdersNotFoundException.java b/src/main/java/com/jangburich/domain/store/exception/OrdersNotFoundException.java new file mode 100644 index 0000000..6328c5d --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/exception/OrdersNotFoundException.java @@ -0,0 +1,7 @@ +package com.jangburich.domain.store.exception; + +public class OrdersNotFoundException extends RuntimeException { + public OrdersNotFoundException() { + super("해당 가게를 찾을 수 없습니다."); + } +} 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 b688145..7dc9ec3 100644 --- a/src/main/java/com/jangburich/domain/store/service/StoreService.java +++ b/src/main/java/com/jangburich/domain/store/service/StoreService.java @@ -33,9 +33,11 @@ import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; import com.jangburich.domain.store.dto.condition.StoreSearchCondition; 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.PaymentGroupDetailResponse; import com.jangburich.domain.store.dto.response.SearchStoresResponse; +import com.jangburich.domain.store.exception.OrdersNotFoundException; import com.jangburich.domain.store.repository.StoreRepository; import com.jangburich.domain.store.repository.StoreTeamRepository; import com.jangburich.domain.team.domain.Team; @@ -271,12 +273,13 @@ public List getOrdersLast(String userId) { 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.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()); Integer price = 0; for (Cart cart : carts) { - price += cart.getMenu().getPrice(); + price += (cart.getMenu().getPrice() * cart.getQuantity()); } newOrdersGetResponse.setPrice(price); ordersGetResponses.add(newOrdersGetResponse); @@ -284,4 +287,37 @@ public List getOrdersLast(String userId) { return ordersGetResponses; } + + public OrdersDetailResponse getOrderDetails(String userId, Long orderId) { + OrdersDetailResponse ordersDetailResponse = new OrdersDetailResponse(); + + userRepository.findByProviderId(userId) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Orders orders = ordersRepository.findById(orderId).orElseThrow(OrdersNotFoundException::new); + + ordersDetailResponse.setId(orders.getId()); + ordersDetailResponse.setTeamName(orders.getTeam().getName()); + ordersDetailResponse.setTeamUserName(orders.getUser().getName()); + + List carts = cartRepository.findAllByOrders(orders); + List menus = new ArrayList<>(); + Integer amount = 0; + Integer price = 0; + for (Cart cart : carts) { + OrdersDetailResponse.Menu menu = new OrdersDetailResponse.Menu(); + menu.setMenuName(cart.getMenu().getName()); + menu.setAmount(cart.getQuantity()); + menus.add(menu); + amount += cart.getQuantity(); + price += (cart.getQuantity() * cart.getMenu().getPrice()); + } + ordersDetailResponse.setMenus(menus); + ordersDetailResponse.setDateTime(orders.getUpdatedAt()); + ordersDetailResponse.setAmount(amount); + ordersDetailResponse.setTotalPrice(price); + ordersDetailResponse.setDiscountPrice(0); + + return ordersDetailResponse; + } } From a1457fe3d84c47593c1892dbbc015faa4a9ad2ee Mon Sep 17 00:00:00 2001 From: HyunWoo9930 Date: Thu, 21 Nov 2024 00:14:54 +0900 Subject: [PATCH 9/9] =?UTF-8?q?feat=20:=20=EB=8B=B9=EC=9D=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/OrdersRepository.java | 12 +++++ .../store/controller/StoreController.java | 10 +++- .../dto/response/OrdersTodayResponse.java | 13 +++++ .../domain/store/service/StoreService.java | 49 ++++++++++++++++++- 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/jangburich/domain/store/dto/response/OrdersTodayResponse.java 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();