From 991ad237552d2e7e0ea45b8a590934e9ee061914 Mon Sep 17 00:00:00 2001 From: Jeonghyun Lee Date: Sat, 14 Sep 2024 16:30:45 +0900 Subject: [PATCH] hotfix: filter default productOrderState --- .../product/dto/productOrder/GetProductOrderForUser.java | 2 ++ .../repick/domain/product/entity/ProductOrderState.java | 4 ++++ .../domain/product/repository/ProductOrderRepository.java | 4 ++-- .../repick/domain/product/scheduler/ProductScheduler.java | 2 +- .../repick/domain/product/service/ProductOrderService.java | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/repick/domain/product/dto/productOrder/GetProductOrderForUser.java b/src/main/java/com/example/repick/domain/product/dto/productOrder/GetProductOrderForUser.java index 48149575..ee2fc3fb 100644 --- a/src/main/java/com/example/repick/domain/product/dto/productOrder/GetProductOrderForUser.java +++ b/src/main/java/com/example/repick/domain/product/dto/productOrder/GetProductOrderForUser.java @@ -6,6 +6,7 @@ public record GetProductOrderForUser( @Schema(description = "주문 아이디") long productOrderId, + @Schema(description = "주문 상태") String orderState, @Schema(description = "브랜드 이름") String brandName, @Schema(description = "상품 이름") String productName, @Schema(description = "상품 이미지 URL") String productImageUrl, @@ -14,6 +15,7 @@ public record GetProductOrderForUser( public static GetProductOrderForUser from(ProductOrder productOrder, Product product) { return new GetProductOrderForUser( productOrder.getId(), + productOrder.getProductOrderState().getValue(), product.getBrandName(), product.getProductName(), product.getThumbnailImageUrl(), diff --git a/src/main/java/com/example/repick/domain/product/entity/ProductOrderState.java b/src/main/java/com/example/repick/domain/product/entity/ProductOrderState.java index 01d018cc..4eaa7957 100644 --- a/src/main/java/com/example/repick/domain/product/entity/ProductOrderState.java +++ b/src/main/java/com/example/repick/domain/product/entity/ProductOrderState.java @@ -4,6 +4,8 @@ import com.example.repick.global.error.exception.ErrorCode; import lombok.Getter; +import java.util.List; + @Getter public enum ProductOrderState { // 주문 관련 @@ -21,6 +23,8 @@ public enum ProductOrderState { private final int id; private final String value; + public static final List ORDERED_STATES = List.of(PAYMENT_COMPLETED, SHIPPING_PREPARING, SHIPPING, DELIVERED); + ProductOrderState(int id, String value) { this.id = id; this.value = value; diff --git a/src/main/java/com/example/repick/domain/product/repository/ProductOrderRepository.java b/src/main/java/com/example/repick/domain/product/repository/ProductOrderRepository.java index 7b4ad204..083b014f 100644 --- a/src/main/java/com/example/repick/domain/product/repository/ProductOrderRepository.java +++ b/src/main/java/com/example/repick/domain/product/repository/ProductOrderRepository.java @@ -14,10 +14,10 @@ public interface ProductOrderRepository extends JpaRepository { List findByPayment(Payment payment); - List findByIsConfirmed(boolean isConfirmed); + List findByIsConfirmedAndProductOrderStateIn(boolean isConfirmed, List productOrderStates); List findByUserId(Long userId); - Page findByUserId(Long userId, Pageable pageable); + Page findByUserIdAndProductOrderStateNot(Long userId, ProductOrderState productOrderState, Pageable pageable); Page findByProductOrderStateIn(List productOrderStates, Pageable pageable); diff --git a/src/main/java/com/example/repick/domain/product/scheduler/ProductScheduler.java b/src/main/java/com/example/repick/domain/product/scheduler/ProductScheduler.java index 85a092c2..06ae0bab 100644 --- a/src/main/java/com/example/repick/domain/product/scheduler/ProductScheduler.java +++ b/src/main/java/com/example/repick/domain/product/scheduler/ProductScheduler.java @@ -75,7 +75,7 @@ else if (days >= 60 && days < 90){ @Scheduled(cron = "0 0 0 * * *") public void confirmProductOrder() { - List productOrders = productOrderRepository.findByIsConfirmed(false); + List productOrders = productOrderRepository.findByIsConfirmedAndProductOrderStateIn(false, ProductOrderState.ORDERED_STATES); productOrders.forEach(po -> { if (Duration.between(po.getCreatedDate(), LocalDateTime.now()).toDays() >= 7) { po.confirmOrder(); diff --git a/src/main/java/com/example/repick/domain/product/service/ProductOrderService.java b/src/main/java/com/example/repick/domain/product/service/ProductOrderService.java index 5efc91b2..fbd7ba6c 100644 --- a/src/main/java/com/example/repick/domain/product/service/ProductOrderService.java +++ b/src/main/java/com/example/repick/domain/product/service/ProductOrderService.java @@ -170,7 +170,7 @@ public PageResponse> getProductOrdersForUser(PageCo User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName()) .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); Pageable pageable = pageCondition.toPageable(); - Page productOrderPage = productOrderRepository.findByUserId(user.getId(), pageable); + Page productOrderPage = productOrderRepository.findByUserIdAndProductOrderStateNot(user.getId(), ProductOrderState.DEFAULT, pageable); List getProductOrders = productOrderPage.stream() .map(productOrder -> { Product product = productRepository.findById(productOrder.getProductId())