diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/GetClothingSales.java b/src/main/java/com/example/repick/domain/clothingSales/dto/GetClothingSales.java index d6b40fe7..8ccb0652 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/GetClothingSales.java +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/GetClothingSales.java @@ -1,16 +1,13 @@ package com.example.repick.domain.clothingSales.dto; -import com.example.repick.domain.clothingSales.entity.BagCollect; import com.example.repick.domain.clothingSales.entity.BoxCollect; import com.example.repick.domain.clothingSales.entity.ClothingSales; import com.example.repick.domain.clothingSales.entity.ClothingSalesStateType; -import com.example.repick.domain.product.entity.Product; import com.example.repick.domain.product.entity.ProductStateType; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import java.time.format.DateTimeFormatter; -import java.util.List; @Builder public record GetClothingSales( @@ -32,7 +29,7 @@ public record GetClothingSales( private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yy"); // 수거 요청일 경우 - public static GetClothingSales ofClothingSales(ClothingSales clothingSales, List products) { + public static GetClothingSales of(ClothingSales clothingSales) { ClothingSalesStateType clothingSalesState = clothingSales.getClothingSalesState(); boolean isBoxCollect = clothingSales instanceof BoxCollect; boolean isProducted = ClothingSalesStateType.AFTER_PRODUCTION.contains(clothingSalesState); @@ -45,23 +42,14 @@ public static GetClothingSales ofClothingSales(ClothingSales clothingSales, List .isBoxCollect(isBoxCollect) .status(clothingSalesState.getAdminValue()) .requestDate(clothingSales.getCreatedDate().format(formatter)) - .isForCollect(clothingSalesState != ClothingSalesStateType.REQUEST_CANCELLED) + .isForCollect(!ClothingSalesStateType.BEFORE_COLLECTION.contains(clothingSalesState)) .productStartDate(isSelling? clothingSales.getProductList().get(0).getSalesStartDate().format(formatter) : null) .salesPeriod(isSelling? clothingSales.getProductList().get(0).getSalesStartDate().format(formatter) + " ~ " + clothingSales.getProductList().get(0).getSalesStartDate().plusDays(90).format(formatter) : null) .settlementRequestDate(clothingSales.getUser().getSettlementRequestDate() != null ? clothingSales.getUser().getSettlementRequestDate().format(formatter) : null) .settlementCompleteDate(clothingSales.getUser().getSettlementCompleteDate() != null ? clothingSales.getUser().getSettlementCompleteDate().format(formatter) : null) - .isRejected(isProducted? products.stream().anyMatch(product -> product.getProductState() == ProductStateType.REJECTED) : null) + .isRejected(isProducted? clothingSales.getProductList().stream().anyMatch(product -> product.getProductState() == ProductStateType.REJECTED) : null) .isExpiredAndReturned(clothingSalesState == ClothingSalesStateType.SELLING_EXPIRED) .build(); } - - public static GetClothingSales ofBagCollect(BagCollect bagCollect) { - return GetClothingSales.builder() - .id(bagCollect.getId()) - .name(bagCollect.getUser().getNickname()) - .status(bagCollect.getClothingSalesState().getAdminValue()) - .requestDate(bagCollect.getCreatedDate().format(formatter)) - .build(); - } } diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSales.java b/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSales.java index acf75335..f2e3429d 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSales.java +++ b/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSales.java @@ -55,6 +55,7 @@ public abstract class ClothingSales { @Column(name = "collection_date") private LocalDate collectionDate; + @Enumerated(EnumType.STRING) private ClothingSalesStateType clothingSalesState; @OneToMany(mappedBy = "clothingSales") diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSalesStateType.java b/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSalesStateType.java index f40f9ebe..deeb5a96 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSalesStateType.java +++ b/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSalesStateType.java @@ -29,6 +29,7 @@ public enum ClothingSalesStateType { private final String sellerValue; private final String adminValue; + public static final List BEFORE_COLLECTION = Arrays.asList(BAG_INIT_REQUEST, REQUEST_CANCELLED, BAG_DELIVERY, BAG_DELIVERED); public static final List AFTER_PRODUCTION = Arrays.asList(PRODUCT_REGISTERED, SELLING, SELLING_EXPIRED); public static final List AFTER_SELLING = Arrays.asList(SELLING, SELLING_EXPIRED); diff --git a/src/main/java/com/example/repick/domain/clothingSales/repository/ClothingSalesRepository.java b/src/main/java/com/example/repick/domain/clothingSales/repository/ClothingSalesRepository.java index fe8eb7c5..4bca7071 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/repository/ClothingSalesRepository.java +++ b/src/main/java/com/example/repick/domain/clothingSales/repository/ClothingSalesRepository.java @@ -3,12 +3,15 @@ import com.example.repick.domain.clothingSales.entity.ClothingSales; import com.example.repick.domain.clothingSales.entity.ClothingSalesStateType; import com.example.repick.domain.user.entity.User; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; import java.util.Optional; public interface ClothingSalesRepository extends JpaRepository { + Page findAllByOrderByCreatedDateDesc(Pageable pageable); List findByUserAndClothingSalesState(User user, ClothingSalesStateType clothingSalesStateType); List findByUserOrderByCreatedDateDesc(User user); Optional findByUserAndClothingSalesCount(User user, Integer clothingSalesCount); diff --git a/src/main/java/com/example/repick/domain/clothingSales/service/BagService.java b/src/main/java/com/example/repick/domain/clothingSales/service/BagService.java index 04213ba3..699ba503 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/service/BagService.java +++ b/src/main/java/com/example/repick/domain/clothingSales/service/BagService.java @@ -65,10 +65,9 @@ public BagCollectResponse registerBagCollect(PostBagCollect postBagCollect) { // BagCollect bagCollect.updateBagCollectInfo(postBagCollect.bagQuantity(), postBagCollect.postalCode(), postBagCollect.mainAddress(), postBagCollect.detailAddress(), postBagCollect.collectionDate()); bagCollect.updateImageUrl(s3UploadService.saveFile(postBagCollect.image(), "clothingSales/bagCollect/" + user.getId() + "/" + bagCollect.getId())); - bagCollectRepository.save(bagCollect); - - // BagCollectState ClothingSalesState clothingSalesState = ClothingSalesState.of(bagCollect.getId(), ClothingSalesStateType.BAG_COLLECT_REQUEST); + bagCollect.updateClothingSalesState(ClothingSalesStateType.BAG_COLLECT_REQUEST); + bagCollectRepository.save(bagCollect); clothingSalesStateRepository.save(clothingSalesState); return BagCollectResponse.of(bagCollect, clothingSalesState.getClothingSalesStateType().getSellerValue()); diff --git a/src/main/java/com/example/repick/domain/clothingSales/service/ClothingSalesService.java b/src/main/java/com/example/repick/domain/clothingSales/service/ClothingSalesService.java index 3b710430..95c229c5 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/service/ClothingSalesService.java +++ b/src/main/java/com/example/repick/domain/clothingSales/service/ClothingSalesService.java @@ -21,8 +21,6 @@ import com.example.repick.global.page.PageResponse; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.Pageable; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -47,7 +45,6 @@ public class ClothingSalesService { private final ClothingSalesRepository clothingSalesRepository; private final ClothingSalesStateRepository clothingSalesStateRepository; private final ProductOrderRepository productOrderRepository; - private final BagCollectRepository bagCollectRepository; public void updateSellingExpired(Product product) { ClothingSalesState clothingSalesState = ClothingSalesState.of(product.getClothingSales().getId(), ClothingSalesStateType.SELLING_EXPIRED); @@ -177,30 +174,10 @@ private ProductQuantityCounter countProductQuantity(List> getClothingSalesInformation(PageCondition pageCondition){ // 수거 신청 정보 조회 - List clothingSalesList = new ArrayList<>(clothingSalesRepository.findAll().stream() - .map(clothingSales -> { - List products = clothingSales.getProductList(); - return GetClothingSales.ofClothingSales(clothingSales, products); - }) - .toList()); - - // 리픽백 배송 요청 정보 조회 - List bagCollectList = bagCollectRepository.findAll().stream() - .map(GetClothingSales::ofBagCollect) - .toList(); - - clothingSalesList.addAll(bagCollectList); - - // createdAt 순서로 내림차순 정렬 - clothingSalesList.sort((o1, o2) -> o2.requestDate().compareTo(o1.requestDate())); - - // Paging 처리 - Pageable pageable = pageCondition.toPageable(); - int start = (int) pageable.getOffset(); - int end = Math.min((start + pageable.getPageSize()), clothingSalesList.size()); - List pagedList = clothingSalesList.subList(start, end); - PageImpl page = new PageImpl<>(pagedList, pageable, clothingSalesList.size()); - return new PageResponse<>(page.getContent(), page.getTotalPages(), page.getTotalElements()); + Page clothingSalesPage = clothingSalesRepository.findAllByOrderByCreatedDateDesc(pageCondition.toPageable()); + List clothingSalesList = clothingSalesPage.stream() + .map(GetClothingSales::of).toList(); + return PageResponse.of(clothingSalesList, clothingSalesPage.getTotalPages(), clothingSalesPage.getTotalElements()); }