From 17479dbcc50875957b229e198febf94efa7c3644 Mon Sep 17 00:00:00 2001 From: Joowon Lim Date: Sun, 3 Dec 2023 22:17:09 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EB=B0=94=EB=A1=9C=20=EC=A3=BC=EB=AC=B8?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../readyverydemo/global/Constant.java | 1 + .../src/order/OrderController.java | 6 +++++ .../readyverydemo/src/order/OrderService.java | 2 ++ .../src/order/OrderServiceImpl.java | 7 +++++ .../src/order/dto/HistoryDetailRes.java | 2 +- .../src/order/dto/OrderMapper.java | 27 ++++++++++++++----- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/readyvery/readyverydemo/global/Constant.java b/src/main/java/com/readyvery/readyverydemo/global/Constant.java index 1cbeae14..361ff468 100644 --- a/src/main/java/com/readyvery/readyverydemo/global/Constant.java +++ b/src/main/java/com/readyvery/readyverydemo/global/Constant.java @@ -7,4 +7,5 @@ public class Constant { public static final String IMG_URL = "/images/"; public static final String USER_CANCEL_RESON = "단순 변심"; public static final Integer EMPTY_CART = 0; + public static final Integer MAX_FASTORDER_SIZE = 5; } diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java index 6de33867..3a0963fe 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java @@ -78,6 +78,12 @@ public ResponseEntity tossPaymentFail( return new ResponseEntity<>(result, HttpStatus.OK); } + @GetMapping("/history/fast") + public ResponseEntity getFastHistories(@AuthenticationPrincipal CustomUserDetails userDetails) { + HistoryRes historyRes = orderService.getFastHistories(userDetails); + return new ResponseEntity<>(historyRes, HttpStatus.OK); + } + @GetMapping("/history/old") public ResponseEntity getHistories(@AuthenticationPrincipal CustomUserDetails userDetails) { HistoryRes historyRes = orderService.getHistories(userDetails); diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java index 601845ff..8a2bbb43 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java @@ -48,4 +48,6 @@ public interface OrderService { CartCountRes getCartCount(CustomUserDetails userDetails); HistoryRes getNewHistories(CustomUserDetails userDetails); + + HistoryRes getFastHistories(CustomUserDetails userDetails); } diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java index 16dc88ef..3ed33eb2 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -349,6 +349,13 @@ public HistoryRes getNewHistories(CustomUserDetails userDetails) { } + @Override + public HistoryRes getFastHistories(CustomUserDetails userDetails) { + UserInfo user = getUserInfo(userDetails); + List orders = getOrders(user); + return orderMapper.ordersToFastOrderRes(orders); + } + private void verifyReceipt(Order order, UserInfo user) { verifyOrderReceipt(order); verifyOrederUser(order, user); diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/HistoryDetailRes.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/HistoryDetailRes.java index 3b578d68..15d14b0c 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/dto/HistoryDetailRes.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/HistoryDetailRes.java @@ -12,7 +12,7 @@ public class HistoryDetailRes { private String orderId; private String storePhone; private CartGetRes cart; - private String salePrice; + private Long salePrice; private String method; private String orderNumber; private Object cancelReason; diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java index 6efda4ea..84c24390 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java @@ -232,21 +232,34 @@ public HistoryRes ordersToHistoryRes(List orders) { .receipts( orders .stream() - .filter(order -> order.getProgress() == PICKUP) + .filter(order -> order.getProgress() == PICKUP + || order.getProgress() == FAIL + || order.getProgress() == CANCEL) .map(this::orderToReceiptHistoryDto) .toList()) .build(); } + public HistoryRes ordersToFastOrderRes(List orders) { + return HistoryRes.builder() + .receipts( + orders + .stream() + .filter(order -> order.getProgress() == COMPLETE + || order.getProgress() == PICKUP) + .map(this::orderToReceiptHistoryDto) + .toList().subList(Math.max(orders.size() - MAX_FASTORDER_SIZE, 0), orders.size())) + .build(); + } + public HistoryRes ordersToNewHistoryRes(List orders) { return HistoryRes.builder() .receipts( orders .stream() - .filter(order -> order.getProgress() != REQUEST) - .filter(order -> order.getProgress() != CANCEL) - .filter(order -> order.getProgress() != PICKUP) - .filter(order -> order.getProgress() != FAIL) + .filter(order -> order.getProgress() == ORDER + || order.getProgress() == MAKE + || order.getProgress() == COMPLETE) .map(this::orderToReceiptHistoryDto) .toList()) .build(); @@ -301,9 +314,9 @@ public HistoryDetailRes orderToHistoryDetailRes(Order order) { .storePhone(order.getStore().getPhone()) .cart(cartToCartGetRes(order.getCart())) .salePrice( - String.valueOf(order.getCoupon() != null + order.getCoupon() != null ? order.getCoupon().getCouponDetail().getSalePrice() - : null)) + : 0L) .method(order.getMethod()) .build(); }