Skip to content

Commit

Permalink
hotfix: filter default productOrderState
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunihs committed Sep 14, 2024
1 parent fc88ca9 commit 991ad23
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.example.repick.global.error.exception.ErrorCode;
import lombok.Getter;

import java.util.List;

@Getter
public enum ProductOrderState {
// ์ฃผ๋ฌธ ๊ด€๋ จ
Expand All @@ -21,6 +23,8 @@ public enum ProductOrderState {
private final int id;
private final String value;

public static final List<ProductOrderState> ORDERED_STATES = List.of(PAYMENT_COMPLETED, SHIPPING_PREPARING, SHIPPING, DELIVERED);

ProductOrderState(int id, String value) {
this.id = id;
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
public interface ProductOrderRepository extends JpaRepository<ProductOrder, Long> {
List<ProductOrder> findByPayment(Payment payment);

List<ProductOrder> findByIsConfirmed(boolean isConfirmed);
List<ProductOrder> findByIsConfirmedAndProductOrderStateIn(boolean isConfirmed, List<ProductOrderState> productOrderStates);

List<ProductOrder> findByUserId(Long userId);
Page<ProductOrder> findByUserId(Long userId, Pageable pageable);
Page<ProductOrder> findByUserIdAndProductOrderStateNot(Long userId, ProductOrderState productOrderState, Pageable pageable);

Page<ProductOrder> findByProductOrderStateIn(List<ProductOrderState> productOrderStates, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ else if (days >= 60 && days < 90){

@Scheduled(cron = "0 0 0 * * *")
public void confirmProductOrder() {
List<ProductOrder> productOrders = productOrderRepository.findByIsConfirmed(false);
List<ProductOrder> productOrders = productOrderRepository.findByIsConfirmedAndProductOrderStateIn(false, ProductOrderState.ORDERED_STATES);
productOrders.forEach(po -> {
if (Duration.between(po.getCreatedDate(), LocalDateTime.now()).toDays() >= 7) {
po.confirmOrder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public PageResponse<List<GetProductOrderForUser>> getProductOrdersForUser(PageCo
User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName())
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));
Pageable pageable = pageCondition.toPageable();
Page<ProductOrder> productOrderPage = productOrderRepository.findByUserId(user.getId(), pageable);
Page<ProductOrder> productOrderPage = productOrderRepository.findByUserIdAndProductOrderStateNot(user.getId(), ProductOrderState.DEFAULT, pageable);
List<GetProductOrderForUser> getProductOrders = productOrderPage.stream()
.map(productOrder -> {
Product product = productRepository.findById(productOrder.getProductId())
Expand Down

0 comments on commit 991ad23

Please sign in to comment.