diff --git a/api-module/src/main/java/com/likelion/apimodule/order/application/OrderFindUseCase.java b/api-module/src/main/java/com/likelion/apimodule/order/application/OrderFindUseCase.java index d2f741f..1d0a090 100644 --- a/api-module/src/main/java/com/likelion/apimodule/order/application/OrderFindUseCase.java +++ b/api-module/src/main/java/com/likelion/apimodule/order/application/OrderFindUseCase.java @@ -67,7 +67,7 @@ public Map> findAllOrdersByDate(String accessToken) { Integer price = 0; for (OrderItem o : orderItems) { Menu singleMenu = menuQueryService.findMenuById(o.getMenu().getId()); - price += singleMenu.getPrice(); + price += singleMenu.getPrice() * o.getQuantity(); } OrderInfo orderInfo = new OrderInfo( diff --git a/api-module/src/main/java/com/likelion/apimodule/payment/service/PaymentService.java b/api-module/src/main/java/com/likelion/apimodule/payment/service/PaymentService.java index 7024c7e..2d1e50b 100644 --- a/api-module/src/main/java/com/likelion/apimodule/payment/service/PaymentService.java +++ b/api-module/src/main/java/com/likelion/apimodule/payment/service/PaymentService.java @@ -23,7 +23,9 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Slf4j @Service @@ -49,10 +51,13 @@ public void approval(String accessToken, ApprovalRequest request) { User user = userQueryService.findByEmail(email); List menuList = new ArrayList<>(); + Map menuQuantityMap = new HashMap<>(); + for (Long id : request.cartIds()) { Cart cart = cartQueryService.findCartById(id); Menu menu = menuQueryService.findMenuById(cart.getMenu().getId()); menuList.add(menu); + menuQuantityMap.put(menu.getId(), cart.getQuantity()); cartQueryService.deleteCartByUserIdAndCartId(user.getUserId(), id); } @@ -60,7 +65,7 @@ public void approval(String accessToken, ApprovalRequest request) { Store store = storeQueryService.findStoreById(menuList.get(0).getId()); // 토스 페이 결제 승인 -// TossPaymentResponse tossPaymentResponse = paymentClient.confirmPayment(request); + // TossPaymentResponse tossPaymentResponse = paymentClient.confirmPayment(request); // 방문 리스트 결제 완료로 저장 + 주문 테이블 저장 marketQueryService.saveVisitListToPayment(store.getId(), user.getEmail()); @@ -71,17 +76,16 @@ public void approval(String accessToken, ApprovalRequest request) { orderQueryService.saveOrder(order); for (Menu value : menuList) { - - Long m = value.getId(); - Menu menu = menuQueryService.findMenuById(m); - Cart cart = cartQueryService.findCartByMenuId(menu.getId()); - int quantity = cart.getQuantity(); + Long menuId = value.getId(); + Menu menu = menuQueryService.findMenuById(menuId); + int quantity = menuQuantityMap.get(menuId); final OrderItem orderItem = OrderItem.builder().order(order).menu(menu).quantity(quantity).build(); orderQueryService.saveOrderItem(orderItem); } } + public String generateOrderNumber(LocalDateTime createdAt) { String datePart = createdAt.format(ORDER_NUMBER_DATE_FORMAT); String randomAlphaNumeric = generateRandomAlphaNumeric();