diff --git a/src/main/java/com/readyvery/readyverydemo/global/Constant.java b/src/main/java/com/readyvery/readyverydemo/global/Constant.java index 1cbeae1..361ff46 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 6de3386..3a0963f 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 601845f..8a2bbb4 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 16dc88e..3ed33eb 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 3b578d6..15d14b0 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 6efda4e..84c2439 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(); }