From 3528da69533aa8bbab5a2b0d8213a8f725d1da51 Mon Sep 17 00:00:00 2001 From: JeongHyun Lee <86969518+hyunihs@users.noreply.github.com> Date: Thu, 1 Aug 2024 11:39:13 +0900 Subject: [PATCH] Refactor: create parent class for BoxCollect, BagCollect (#119) * refactor: create parent class for BoxCollect, BagCollect * chore: delete unused import * fix: get user Info from clothingSalesId * fix: get clothingSales api * refactor: builder pattern in dto * fix: enable createdDate on clothingSales * fix: register product * fix: get ClothingSalesProductCount * refactor: reduce query for pendingClothingSales --- .../api/ClothingSalesController.java | 54 +-- .../clothingSales/dto/BagCollectResponse.java | 4 +- .../clothingSales/dto/BagInitResponse.java | 2 - .../domain/clothingSales/dto/BagState.java | 6 - .../clothingSales/dto/BoxCollectResponse.java | 2 +- .../clothingSales/dto/GetClothingSales.java | 87 ++-- .../dto/GetPendingClothingSales.java | 25 +- .../dto/GetSellingClothingSales.java | 17 +- .../dto/PatchClothingSalesWeight.java | 9 + .../clothingSales/dto/PostBagCollect.java | 8 +- .../dto/PostBagCollectState.java | 9 - .../domain/clothingSales/dto/PostBagInit.java | 6 +- .../clothingSales/dto/PostBagInitState.java | 9 - .../clothingSales/dto/PostBoxCollect.java | 4 +- .../dto/PostBoxCollectState.java | 9 - .../clothingSales/dto/PostClothingSales.java | 9 - .../dto/PostClothingSalesState.java | 4 +- .../dto/PostClothingSalesWeight.java | 11 - .../clothingSales/entity/BagCollect.java | 49 +-- .../clothingSales/entity/BagCollectState.java | 38 -- .../entity/BagCollectStateType.java | 70 --- .../domain/clothingSales/entity/BagInit.java | 42 +- .../entity/BagInitStateType.java | 51 +-- .../clothingSales/entity/BoxCollect.java | 68 +-- .../clothingSales/entity/BoxCollectState.java | 38 -- .../entity/BoxCollectStateType.java | 70 --- .../clothingSales/entity/ClothingSales.java | 91 ++++ .../entity/ClothingSalesState.java | 33 ++ .../entity/ClothingSalesStateType.java | 59 ++- .../repository/BagCollectRepository.java | 5 +- .../BagCollectRepositoryCustom.java | 4 - .../repository/BagCollectRepositoryImpl.java | 13 - .../repository/BagCollectStateRepository.java | 7 - .../repository/BagInitRepository.java | 6 - .../repository/BagInitStateRepository.java | 5 + .../repository/BoxCollectRepository.java | 7 - .../repository/BoxCollectStateRepository.java | 7 - .../repository/ClothingSalesRepository.java | 16 + .../ClothingSalesStateRepository.java | 10 + .../clothingSales/service/BagService.java | 43 +- .../clothingSales/service/BoxService.java | 35 +- .../service/ClothingSalesService.java | 398 +++++------------- .../validator/ClothingSalesValidator.java | 23 - .../product/dto/product/PostProduct.java | 7 +- .../repick/domain/product/entity/Product.java | 10 + .../repository/ProductOrderRepository.java | 4 + .../repository/ProductRepositoryCustom.java | 6 +- .../repository/ProductRepositoryImpl.java | 34 +- .../product/service/ProductService.java | 14 +- .../product/validator/ProductValidator.java | 33 -- .../global/error/exception/ErrorCode.java | 10 +- 51 files changed, 515 insertions(+), 1066 deletions(-) delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/dto/BagState.java create mode 100644 src/main/java/com/example/repick/domain/clothingSales/dto/PatchClothingSalesWeight.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/dto/PostBagCollectState.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/dto/PostBagInitState.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/dto/PostBoxCollectState.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSales.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSalesWeight.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/entity/BagCollectState.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/entity/BagCollectStateType.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollectState.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollectStateType.java create mode 100644 src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSales.java create mode 100644 src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSalesState.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepositoryCustom.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepositoryImpl.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectStateRepository.java delete mode 100644 src/main/java/com/example/repick/domain/clothingSales/repository/BoxCollectStateRepository.java create mode 100644 src/main/java/com/example/repick/domain/clothingSales/repository/ClothingSalesRepository.java create mode 100644 src/main/java/com/example/repick/domain/clothingSales/repository/ClothingSalesStateRepository.java diff --git a/src/main/java/com/example/repick/domain/clothingSales/api/ClothingSalesController.java b/src/main/java/com/example/repick/domain/clothingSales/api/ClothingSalesController.java index 8473a018..df38459b 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/api/ClothingSalesController.java +++ b/src/main/java/com/example/repick/domain/clothingSales/api/ClothingSalesController.java @@ -25,7 +25,7 @@ public class ClothingSalesController { @Operation(summary = "백 초기 요청", description = """ 백 초기 요청을 합니다. - 백 초기 요청 등록 시 '대기중' 상태로 등록됩니다. + 백 초기 요청 등록 시 '신청 완료' 상태로 등록됩니다. MediaType: multipart/form-data """) @@ -36,7 +36,7 @@ public SuccessResponse handleBagInit(@ModelAttribute PostBagIni @Operation(summary = "백 수거 요청", description = """ 백 수거 요청을 합니다. - 백 수거 요청 등록 시 '대기중' 상태로 등록됩니다. + 백 수거 요청 등록 시 '신청 완료' 상태로 등록됩니다. MediaType: multipart/form-data """) @@ -47,8 +47,8 @@ public SuccessResponse handleRepickBagCollectionRequest(@Mod @Operation(summary = "박스 수거 요청", description = """ 박스 수거 요청을 합니다. - 박스 수거 요청 등록 시 '대기중' 상태로 등록됩니다. - + 박스 수거 요청 등록 시 '신청 완료' 상태로 등록됩니다. + MediaType: multipart/form-data """) @PostMapping(value = "/box/collection", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @@ -58,28 +58,14 @@ public SuccessResponse handleBoxCollectionRequest(@ModelAttr @Operation(summary = "옷장 정리 통합 조회: 진행 중인 수거", description = """ 옷장 정리 통합 조회: 진행 중인 수거, 신청 완료일 순으로 정렬되어 리스트로 반환합니다. - - id: 수거 ID, '백 수거 요청' 시 '백 요청 ID'를 조회하기 위해 사용됩니다. - - clothingSalesCount: 수거 회차(각각의 유저에 대해 고유한 값입니다). - - type: 박스/백 - - requestDate: 신청 완료일 - - bagArriveDate: 백 도착일 (박스의 경우 항상 null) - - collectDate: 수거 완료일 - - productDate: 상품화 완료일 """) @GetMapping("/pending") public SuccessResponse> getPendingClothingSales() { - return SuccessResponse.createSuccess(clothingSalesService.getPendingClothingSales()); + return SuccessResponse.success(clothingSalesService.getPendingClothingSales()); } @Operation(summary = "옷장 정리 통합 조회: 판매 중인 옷장", description = """ - 옷장 정리 통합 조회: 판매 중인 옷장, 신청 완료일 순으로 정렬되어 리스트로 반환합니다. - - id: 수거 ID - - clothingSalesCount: 수거 회차(각각의 유저에 대해 고유한 값입니다). - - clothingSalesPeriod: 신청 완료일 ~ 판매 진행 시작일 - - sellingQuantity: 판매 중인 의류 수량 - - pendingQuantity: 구매 확정 대기 수량 - - soldQuantity: 판매 완료 수량 - - totalPoint: 총 포인트 + 옷장 정리 통합 조회: 판매 중인 옷장, 신청 완료일 내림차순으로 정렬되어 리스트로 반환합니다. """) @GetMapping("/selling") public SuccessResponse> getSellingClothingSales() { @@ -92,9 +78,9 @@ public SuccessResponse> getSellingClothingSales() - requestedQuantity: 신청한 의류 수량 - productQuantity: 판매 가능한 의류 수량 """) - @GetMapping("/products/{clothingSalesCount}") - public SuccessResponse getProductsByClothingSalesCount(@PathVariable Integer clothingSalesCount) { - return SuccessResponse.success(clothingSalesService.getProductsByClothingSalesCount(clothingSalesCount)); + @GetMapping("/products/{clothingSalesId}") + public SuccessResponse getProductsByClothingSalesId(@PathVariable Long clothingSalesId) { + return SuccessResponse.success(clothingSalesService.getProductsByClothingSalesId(clothingSalesId)); } @Operation(summary = "상품 가격 입력하기", description = """ @@ -108,7 +94,7 @@ public SuccessResponse getProductsByClothingSales """) @PatchMapping("/products/price") public SuccessResponse updateProductPrice(@RequestBody List postProductPriceList) { - return SuccessResponse.createSuccess(clothingSalesService.updateProductPrice(postProductPriceList)); + return SuccessResponse.success(clothingSalesService.updateProductPrice(postProductPriceList)); } // TODO: ADMIN ACCESS @@ -136,24 +122,24 @@ public SuccessResponse>> getClot } @Operation(summary = "유저 상품 현황") - @GetMapping("/products/{userId}/{clothingSalesCount}/{productStateType}") - public SuccessResponse>> getClothingSalesProduct(@PathVariable Long userId, - @PathVariable Integer clothingSalesCount, + @GetMapping("/products/{clothingSalesId}/{productStateType}") + public SuccessResponse>> getClothingSalesProduct(@PathVariable Long clothingSalesId, @PathVariable ProductStateType productStateType, @ParameterObject PageCondition pageCondition) { - return SuccessResponse.success(clothingSalesService.getClothingSalesProduct(userId, clothingSalesCount, productStateType, pageCondition)); + return SuccessResponse.success(clothingSalesService.getClothingSalesProduct(clothingSalesId, productStateType, pageCondition)); } @Operation(summary = "옷장 정리 상품 무게 등록") - @PostMapping("/weight") - public SuccessResponse updateClothingSalesWeight(@RequestBody PostClothingSalesWeight postClothingSalesWeight) { - return SuccessResponse.success(clothingSalesService.updateClothingSalesWeight(postClothingSalesWeight)); + @PatchMapping("/weight") + public SuccessResponse updateClothingSalesWeight(@RequestBody PatchClothingSalesWeight patchClothingSalesWeight) { + clothingSalesService.updateClothingSalesWeight(patchClothingSalesWeight); + return SuccessResponse.success(true); } @Operation(summary = "옷장 정리 유저 정보") - @GetMapping("/{userId}/{clothingSalesCount}") - public SuccessResponse getClothingSalesUserInfo(@PathVariable Long userId, @PathVariable Integer clothingSalesCount) { - return SuccessResponse.success(clothingSalesService.getClothingSalesUser(userId, clothingSalesCount)); + @GetMapping("/{clothingSalesId}") + public SuccessResponse getClothingSalesUserInfo(@PathVariable Long clothingSalesId) { + return SuccessResponse.success(clothingSalesService.getClothingSalesUser(clothingSalesId)); } } diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/BagCollectResponse.java b/src/main/java/com/example/repick/domain/clothingSales/dto/BagCollectResponse.java index c8ea5a53..8944cace 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/BagCollectResponse.java +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/BagCollectResponse.java @@ -9,13 +9,13 @@ public record BagCollectResponse( @Schema(description = "의류 사진 url", example = "https://repick.s3.ap-northeast-2.amazonaws.com/repick/2021/09/15/1631690136_1.jpg") String imageUrl, @Schema(description = "백 수량", example = "3") Integer bagQuantity, Address address, - @Schema(description = "백 상태", example = "대기중") String bagInitState + @Schema(description = "백 상태", example = "신청 완료") String bagCollectState ) { public static BagCollectResponse of(BagCollect bagCollect, String bagCollectStateType) { return new BagCollectResponse( bagCollect.getId(), bagCollect.getImageUrl(), - bagCollect.getBagQuantity(), + bagCollect.getQuantity(), bagCollect.getAddress(), bagCollectStateType ); diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/BagInitResponse.java b/src/main/java/com/example/repick/domain/clothingSales/dto/BagInitResponse.java index bc5a6bbc..30ce9e00 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/BagInitResponse.java +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/BagInitResponse.java @@ -6,7 +6,6 @@ public record BagInitResponse( @Schema(description = "백 초기 요청 ID", example = "1") Long bagInitId, - @Schema(description = "의류 사진 url", example = "https://repick.s3.ap-northeast-2.amazonaws.com/repick/2021/09/15/1631690136_1.jpg") String imageUrl, @Schema(description = "백 수량", example = "3") Integer bagQuantity, Address address, @Schema(description = "백 상태", example = "대기중") String bagInitState @@ -14,7 +13,6 @@ public record BagInitResponse( public static BagInitResponse of(BagInit bagInit, String bagInitStateType) { return new BagInitResponse( bagInit.getId(), - bagInit.getImageUrl(), bagInit.getBagQuantity(), bagInit.getAddress(), bagInitStateType diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/BagState.java b/src/main/java/com/example/repick/domain/clothingSales/dto/BagState.java deleted file mode 100644 index ab4130df..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/BagState.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.example.repick.domain.clothingSales.dto; - -public record BagState( - -) { -} diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/BoxCollectResponse.java b/src/main/java/com/example/repick/domain/clothingSales/dto/BoxCollectResponse.java index bb211c38..e43fcdf5 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/BoxCollectResponse.java +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/BoxCollectResponse.java @@ -15,7 +15,7 @@ public static BoxCollectResponse of(BoxCollect boxCollect, String boxCollectStat return new BoxCollectResponse( boxCollect.getId(), boxCollect.getImageUrl(), - boxCollect.getBoxQuantity(), + boxCollect.getQuantity(), boxCollect.getAddress(), boxCollectStateType ); 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 05f788c0..1cb6fdf3 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,25 +1,23 @@ package com.example.repick.domain.clothingSales.dto; -import com.example.repick.domain.clothingSales.entity.BagInit; -import com.example.repick.domain.clothingSales.entity.BoxCollect; -import com.example.repick.domain.clothingSales.entity.ClothingSalesStateType; -import com.example.repick.domain.product.entity.Product; +import com.example.repick.domain.clothingSales.entity.*; import com.example.repick.domain.product.entity.ProductState; 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( + @Schema(description = "옷장 정리 id (리픽백 배송 요청인 경우 리픽백 배송 요청 id)") Long id, + @Schema(description = "(백일 경우) 백 배송 여부, true: 백 배송까지 단계 false: 백 수거부터") Boolean isBagDelivered, @Schema(description = "코드") String code, @Schema(description = "이름") String name, - @Schema(description = "유저 ID") Long userId, - @Schema(description = "옷장 정리 회차") Integer clothingSalesCount, @Schema(description = "박스 수거 여부, true: 박스 수거 false: 백 수거", example = "true") Boolean isBoxCollect, @Schema(description = "현황") String status, @Schema(description = "신청일") String requestDate, - @Schema(description = "(백일 경우) 백 배송 여부, true: 백 배송까지 단계 false: 백 수거부터") Boolean isBagDelivered, @Schema(description = "수거 진행 여부") Boolean isForCollect, @Schema(description = "상품화 시작일") String productStartDate, @Schema(description = "판매기간") String salesPeriod, @@ -29,47 +27,42 @@ public record GetClothingSales( @Schema(description = "판매만료 리턴") Boolean isExpiredAndReturned ) { - public static GetClothingSales of(BoxCollect boxCollect, List products, List productStates) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); - return new GetClothingSales( - boxCollect.getUser().getId().toString() + "-" + boxCollect.getClothingSalesCount(), - boxCollect.getUser().getNickname(), - boxCollect.getUser().getId(), - boxCollect.getClothingSalesCount(), - true, - boxCollect.getClothingSalesState().getValue(), - boxCollect.getCreatedDate().format(formatter), - null, - boxCollect.getClothingSalesState() != ClothingSalesStateType.REQUEST_CANCELLED, - boxCollect.getClothingSalesState().getId() >= 14 ? products.get(0).getSalesStartDate().format(formatter) : null, - boxCollect.getClothingSalesState().getId() >= 14 ? products.get(0).getSalesStartDate().format(formatter) - + " ~ " + products.get(0).getSalesStartDate().plusDays(90).format(formatter) : null, - boxCollect.getUser().getSettlementRequestDate() != null ? boxCollect.getUser().getSettlementRequestDate().format(formatter) : null, - boxCollect.getUser().getSettlementCompleteDate() != null ? boxCollect.getUser().getSettlementCompleteDate().format(formatter) : null, - boxCollect.getClothingSalesState().getId() >= 13? productStates.stream().anyMatch(productState -> productState.getProductStateType() == ProductStateType.REJECTED) : null, - boxCollect.getClothingSalesState() == ClothingSalesStateType.SELLING_EXPIRED - ); + private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yy"); + + // 수거 요청일 경우 + public static GetClothingSales ofClothingSales(ClothingSales clothingSales, List productStates) { + ClothingSalesStateType clothingSalesState = clothingSales.getClothingSalesState(); + boolean isBoxCollect = clothingSales instanceof BoxCollect; + boolean isProducted = ClothingSalesStateType.AFTER_PRODUCTION.contains(clothingSalesState); + boolean isSelling = ClothingSalesStateType.AFTER_SELLING.contains(clothingSalesState); + + return GetClothingSales.builder() + .id(clothingSales.getId()) + .isBagDelivered(isBoxCollect? null : true) + .code(clothingSales.getUser().getId().toString() + "-" + clothingSales.getClothingSalesCount()) + .name(clothingSales.getUser().getNickname()) + .isBoxCollect(isBoxCollect) + .status(clothingSalesState.getAdminValue()) + .requestDate(clothingSales.getCreatedDate().format(formatter)) + .isForCollect(clothingSalesState != ClothingSalesStateType.REQUEST_CANCELLED) + .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? productStates.stream().anyMatch(productState -> productState.getProductStateType() == ProductStateType.REJECTED) : null) + .isExpiredAndReturned(clothingSalesState == ClothingSalesStateType.SELLING_EXPIRED) + .build(); } - public static GetClothingSales of(BagInit bagInit, List products, List productStates) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); - return new GetClothingSales( - bagInit.getUser().getId().toString() + "-" + bagInit.getClothingSalesCount(), - bagInit.getUser().getNickname(), - bagInit.getUser().getId(), - bagInit.getClothingSalesCount(), - false, - bagInit.getClothingSalesState() != ClothingSalesStateType.BAG_COLLECT_REQUEST? bagInit.getClothingSalesState().getValue() : "리픽백 배송 완료", - bagInit.getCreatedDate().format(formatter), - bagInit.getBagCollect() != null, - bagInit.getClothingSalesState().getId() >= 6, - bagInit.getClothingSalesState().getId() >= 14 ? products.get(0).getSalesStartDate().format(formatter) : null, - bagInit.getClothingSalesState().getId() >= 14 ? products.get(0).getSalesStartDate().format(formatter) - + " ~ " + products.get(0).getSalesStartDate().plusDays(90).format(formatter) : null, - bagInit.getUser().getSettlementRequestDate() != null ? bagInit.getUser().getSettlementRequestDate().format(formatter) : null, - bagInit.getUser().getSettlementCompleteDate() != null ? bagInit.getUser().getSettlementCompleteDate().format(formatter) : null, - bagInit.getClothingSalesState().getId() >= 13? productStates.stream().anyMatch(productState -> productState.getProductStateType() == ProductStateType.REJECTED) : null, - bagInit.getClothingSalesState() == ClothingSalesStateType.SELLING_EXPIRED - ); + // 백 배송 요청일 경우 + public static GetClothingSales ofBagInit(BagInit bagInit, BagInitState bagInitState) { + return GetClothingSales.builder() + .id(bagInit.getId()) + .isBagDelivered(false) + .name(bagInit.getUser().getNickname()) + .status(bagInitState.getBagInitStateType().getAdminValue()) + .requestDate(bagInit.getCreatedDate().format(formatter)) + .build(); } } diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/GetPendingClothingSales.java b/src/main/java/com/example/repick/domain/clothingSales/dto/GetPendingClothingSales.java index 80f33795..32ad0179 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/GetPendingClothingSales.java +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/GetPendingClothingSales.java @@ -1,24 +1,29 @@ package com.example.repick.domain.clothingSales.dto; +import com.example.repick.domain.clothingSales.entity.BoxCollect; +import com.example.repick.domain.clothingSales.entity.ClothingSales; import io.swagger.v3.oas.annotations.media.Schema; +import java.time.LocalDateTime; + + public record GetPendingClothingSales( @Schema(description = "수거 ID", example = "1") Long id, @Schema(description = "옷장 정리 회차", example = "1") Integer clothingSalesCount, - @Schema(description = "타입(박스/백)", example = "박스") String type, - @Schema(description = "신청 완료일", example = "24.09.15") String requestDate, - @Schema(description = "백 도착일", example = "24.09.16") String bagArriveDate, - @Schema(description = "수거 완료일", example = "24.09.17") String collectDate, - @Schema(description = "상품화 완료일", example = "24.09.18") String productDate + @Schema(description = "박스 수거 여부 true: 박스 수거, false: 리픽백 수거") boolean isBoxCollect, + @Schema(description = "신청 완료일") LocalDateTime requestDate, + @Schema(description = "수거 완료일") LocalDateTime collectDate, + @Schema(description = "상품 촬영일") LocalDateTime shootDate, + @Schema(description = "상품화 완료일") LocalDateTime productDate ) { - public static GetPendingClothingSales of(Long id, Integer clothingSalesCount, String type, String requestDate, String bagArriveDate, String collectDate, String productDate) { + public static GetPendingClothingSales of(ClothingSales clothingSales, LocalDateTime requestDate, LocalDateTime collectDate, LocalDateTime shootDate, LocalDateTime productDate) { return new GetPendingClothingSales( - id, - clothingSalesCount, - type, + clothingSales.getId(), + clothingSales.getClothingSalesCount(), + clothingSales instanceof BoxCollect, requestDate, - bagArriveDate, collectDate, + shootDate, productDate ); } diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/GetSellingClothingSales.java b/src/main/java/com/example/repick/domain/clothingSales/dto/GetSellingClothingSales.java index 30d89038..c5ce6293 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/GetSellingClothingSales.java +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/GetSellingClothingSales.java @@ -1,14 +1,29 @@ package com.example.repick.domain.clothingSales.dto; +import com.example.repick.domain.clothingSales.entity.ClothingSales; import io.swagger.v3.oas.annotations.media.Schema; + public record GetSellingClothingSales( @Schema(description = "수거 ID", example = "1") Long id, @Schema(description = "옷장 정리 회차", example = "1") Integer clothingSalesCount, - @Schema(description = "판매 진행 시작일 ~ +90일", example = "24.01.05-24.04.05") String clothingSalesPeriod, + @Schema(description = "판매 진행 시작일", example = "2024.01.01") String salesStartDate, + @Schema(description = "남은 판매 일수", example= "90") Integer remainingSalesDays, @Schema(description = "판매 중인 의류 수량", example = "43") Integer sellingQuantity, @Schema(description = "구매 확정 대기 수량", example = "7") Integer pendingQuantity, @Schema(description = "구매 확정 완료 수량", example = "36") Integer soldQuantity, @Schema(description = "총 포인트", example = "2300") Long totalPoint ) { + + public static GetSellingClothingSales of(ClothingSales clothingSales, String salesStartDate, int remainingSalesDays, int sellingQuantity, int pendingQuantity, int soldQuantity) { + return new GetSellingClothingSales( + clothingSales.getId(), + clothingSales.getClothingSalesCount(), + salesStartDate, + remainingSalesDays, + sellingQuantity, + pendingQuantity, + soldQuantity, + clothingSales.getPoint()); + } } diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/PatchClothingSalesWeight.java b/src/main/java/com/example/repick/domain/clothingSales/dto/PatchClothingSalesWeight.java new file mode 100644 index 00000000..8e0f07d2 --- /dev/null +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/PatchClothingSalesWeight.java @@ -0,0 +1,9 @@ +package com.example.repick.domain.clothingSales.dto; + +import io.swagger.v3.oas.annotations.media.Schema; + +public record PatchClothingSalesWeight( + @Schema(description = "옷장 정리 ID") Long clothingSalesId, + @Schema(description = "무게") Double weight +) { +} diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagCollect.java b/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagCollect.java index 4d0df140..b6146778 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagCollect.java +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagCollect.java @@ -2,6 +2,7 @@ import com.example.repick.domain.clothingSales.entity.BagCollect; import com.example.repick.domain.clothingSales.entity.BagInit; +import com.example.repick.domain.clothingSales.entity.ClothingSalesStateType; import com.example.repick.domain.user.entity.User; import com.example.repick.global.entity.Address; import io.swagger.v3.oas.annotations.media.Schema; @@ -19,13 +20,16 @@ public record PostBagCollect ( @Schema(description = "희망 수거 날짜", example = "2021-09-15") String collectionDate ) { - public BagCollect toEntity(BagInit bagInit, User user) { + public BagCollect toEntity(BagInit bagInit, User user, int clothingSalesCount) { return BagCollect.builder() .user(user) .bagInit(bagInit) - .bagQuantity(bagQuantity) + .quantity(bagQuantity) .address(new Address(postalCode, mainAddress, detailAddress)) .collectionDate(LocalDate.parse(collectionDate)) + .clothingSalesCount(clothingSalesCount) + .point(0L) + .clothingSalesState(ClothingSalesStateType.BAG_COLLECT_REQUEST) .build(); } } diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagCollectState.java b/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagCollectState.java deleted file mode 100644 index 6219f7b7..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagCollectState.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.example.repick.domain.clothingSales.dto; - -import io.swagger.v3.oas.annotations.media.Schema; - -public record PostBagCollectState( - @Schema(description = "백 수거 요청 ID", example = "3") Long bagCollectId, - @Schema(description = "백 수거 요청 상태", example = "수거완료") String bagCollectStateType -) { -} diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagInit.java b/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagInit.java index 2cc8d0b8..9c86caf2 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagInit.java +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagInit.java @@ -1,7 +1,6 @@ package com.example.repick.domain.clothingSales.dto; import com.example.repick.domain.clothingSales.entity.BagInit; -import com.example.repick.domain.clothingSales.entity.ClothingSalesStateType; import com.example.repick.domain.user.entity.User; import com.example.repick.global.entity.Address; import io.swagger.v3.oas.annotations.media.Schema; @@ -16,14 +15,11 @@ public record PostBagInit( ) { - public BagInit toEntity(User user, Integer clothingSalesCount) { + public BagInit toEntity(User user) { return BagInit.builder() .user(user) .bagQuantity(bagQuantity) .address(new Address(postalCode, mainAddress, detailAddress)) - .clothingSalesState(ClothingSalesStateType.BAG_REQUEST) - .clothingSalesCount(clothingSalesCount) - .point(0L) .build(); } diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagInitState.java b/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagInitState.java deleted file mode 100644 index ad7760af..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBagInitState.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.example.repick.domain.clothingSales.dto; - -import io.swagger.v3.oas.annotations.media.Schema; - -public record PostBagInitState( - @Schema(description = "백 초기 요청 ID", example = "3") Long bagInitId, - @Schema(description = "백 초기 요청 상태", example = "배송중") String bagInitStateType -) { -} diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBoxCollect.java b/src/main/java/com/example/repick/domain/clothingSales/dto/PostBoxCollect.java index bc99684e..98e3036f 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBoxCollect.java +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/PostBoxCollect.java @@ -21,12 +21,12 @@ public record PostBoxCollect ( public BoxCollect toEntity(User user, Integer clothingSalesCount) { return BoxCollect.builder() .user(user) - .boxQuantity(boxQuantity) + .quantity(boxQuantity) .address(new Address(postalCode, mainAddress, detailAddress)) .collectionDate(LocalDate.parse(collectionDate)) - .clothingSalesState(ClothingSalesStateType.BOX_REQUEST) .clothingSalesCount(clothingSalesCount) .point(0L) + .clothingSalesState(ClothingSalesStateType.BOX_COLLECT_REQUEST) .build(); } } diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBoxCollectState.java b/src/main/java/com/example/repick/domain/clothingSales/dto/PostBoxCollectState.java deleted file mode 100644 index 10dc2605..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/PostBoxCollectState.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.example.repick.domain.clothingSales.dto; - -import io.swagger.v3.oas.annotations.media.Schema; - -public record PostBoxCollectState( - @Schema(description = "박스 수거 요청 ID", example = "3") Long boxCollectId, - @Schema(description = "박스 수거 요청 상태", example = "판매진행") String boxCollectStateType -) { -} diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSales.java b/src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSales.java deleted file mode 100644 index 58eadde8..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSales.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.example.repick.domain.clothingSales.dto; - -import io.swagger.v3.oas.annotations.media.Schema; - -public record PostClothingSales( - @Schema(description = "유저 ID", example = "1") Long userId, - @Schema(description = "수거 회차", example = "3") Integer clothingSalesCount -) { -} diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSalesState.java b/src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSalesState.java index 7833ee7e..1617f4f1 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSalesState.java +++ b/src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSalesState.java @@ -3,10 +3,8 @@ import io.swagger.v3.oas.annotations.media.Schema; public record PostClothingSalesState( - @Schema(description = "박스 수거 여부, true: 박스 수거 false: 백 수거", example = "true") Boolean isBoxCollect, @Schema(description = "(백일 경우) 백 배송 여부, true: 백 배송까지 단계 false: 백 수거부터") Boolean isBagDelivered, - @Schema(description = "유저 ID") Long userId, - @Schema(description = "옷장 정리 회차") Integer clothingSalesCount, + @Schema(description = "옷장 정리 id (리픽백 배송 요청인 경우 리픽백 배송 요청 id)") Long id, @Schema(description = "상태") String clothingSalesState ) { diff --git a/src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSalesWeight.java b/src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSalesWeight.java deleted file mode 100644 index d1fa7fdf..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/dto/PostClothingSalesWeight.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.example.repick.domain.clothingSales.dto; - -import io.swagger.v3.oas.annotations.media.Schema; - -public record PostClothingSalesWeight( - @Schema(description = "유저 ID") Long userId, - @Schema(description = "옷장 정리 회차") Integer clothingSalesCount, - @Schema(description = "박스 수거 여부") Boolean isBoxCollect, - @Schema(description = "무게") Double weight -) { -} diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/BagCollect.java b/src/main/java/com/example/repick/domain/clothingSales/entity/BagCollect.java index b9cb9318..f4ab88bb 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/entity/BagCollect.java +++ b/src/main/java/com/example/repick/domain/clothingSales/entity/BagCollect.java @@ -1,61 +1,18 @@ package com.example.repick.domain.clothingSales.entity; -import com.example.repick.domain.user.entity.User; -import com.example.repick.global.entity.Address; -import com.example.repick.global.entity.BaseEntity; import jakarta.persistence.*; import lombok.AccessLevel; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; - -import java.time.LocalDate; -import java.util.List; +import lombok.experimental.SuperBuilder; @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class BagCollect extends BaseEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - private Long id; +@SuperBuilder +public class BagCollect extends ClothingSales{ @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id") - private User user; - - @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "bag_init_id") private BagInit bagInit; - @Embedded - private Address address; - - @Column(name = "bag_quantity") - private Integer bagQuantity; - - @Column(name = "image_url", length = 1000) - private String imageUrl; - - @Column(name = "collection_date") - private LocalDate collectionDate; - - @OneToMany(mappedBy = "bagCollect", cascade = CascadeType.ALL) - private List bagCollectStateList; - - @Builder - public BagCollect(User user, BagInit bagInit, Address address, Integer bagQuantity, String imageUrl, LocalDate collectionDate) { - this.user = user; - this.bagInit = bagInit; - this.address = address; - this.bagQuantity = bagQuantity; - this.imageUrl = imageUrl; - this.collectionDate = collectionDate; - } - - public void updateImageUrl(String imageUrl) { - this.imageUrl = imageUrl; - } - } diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/BagCollectState.java b/src/main/java/com/example/repick/domain/clothingSales/entity/BagCollectState.java deleted file mode 100644 index 13be6415..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/entity/BagCollectState.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.example.repick.domain.clothingSales.entity; - -import com.example.repick.global.entity.BaseEntity; -import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class BagCollectState extends BaseEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Enumerated(EnumType.STRING) - private BagCollectStateType bagCollectStateType; - - @ManyToOne - @JoinColumn(name = "bag_collect_id") - private BagCollect bagCollect; - - @Builder - public BagCollectState(BagCollectStateType bagCollectStateType, BagCollect bagCollect) { - this.bagCollectStateType = bagCollectStateType; - this.bagCollect = bagCollect; - } - - public static BagCollectState of(BagCollectStateType bagCollectStateType, BagCollect bagCollect) { - return BagCollectState.builder() - .bagCollectStateType(bagCollectStateType) - .bagCollect(bagCollect) - .build(); - } - -} \ No newline at end of file diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/BagCollectStateType.java b/src/main/java/com/example/repick/domain/clothingSales/entity/BagCollectStateType.java deleted file mode 100644 index c3cbc785..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/entity/BagCollectStateType.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.example.repick.domain.clothingSales.entity; - -import com.example.repick.global.error.exception.CustomException; -import com.example.repick.global.error.exception.ErrorCode; - -public enum BagCollectStateType { - PENDING(1, "신청완료"), - DELIVERING(2, "수거중"), - DELIVERED(3, "수거완료"), - INSPECTION_COMPLETED(4, "검수완료"), - SELLING(5, "판매진행"), - CANCELED(6, "요청취소"); - - private final int id; - private final String value; - - BagCollectStateType(int id, String value) { - this.id = id; - this.value = value; - } - - public int getId() { - return id; - } - - public String getValue() { - return value; - } - - public static BagCollectStateType fromId(int id) { - for (BagCollectStateType bagCollectStateType : values()) { - if (bagCollectStateType.getId() == id) { - return bagCollectStateType; - } - } - throw new CustomException(ErrorCode.INVALID_BAG_COLLECT_STATUS_ID); - } - - public static BagCollectStateType fromValue(String keyword) { - for (BagCollectStateType bagCollectStateType : values()) { - if (bagCollectStateType.getValue().equals(keyword)) { - return bagCollectStateType; - } - } - throw new CustomException(ErrorCode.INVALID_BAG_COLLECT_STATUS_NAME); - } - - public static BagCollectStateType fromClothingSalesStateType(ClothingSalesStateType clothingSalesStateType) { - switch (clothingSalesStateType) { - case COLLECTING -> { - return BagCollectStateType.DELIVERING; - } - case COLLECTED -> { - return BagCollectStateType.DELIVERED; - } - case REQUEST_CANCELLED -> { - return BagCollectStateType.CANCELED; - } - case SHOOTING, SHOOTED, PRODUCTING, PRODUCTED -> { - return null; - } - case PRODUCT_REGISTERED -> { - return BagCollectStateType.INSPECTION_COMPLETED; - } - default -> { - throw new CustomException(ErrorCode.INVALID_BAG_COLLECT_STATUS_NAME); - } - } - } -} diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/BagInit.java b/src/main/java/com/example/repick/domain/clothingSales/entity/BagInit.java index 51ef06c0..2c4b78e2 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/entity/BagInit.java +++ b/src/main/java/com/example/repick/domain/clothingSales/entity/BagInit.java @@ -30,52 +30,16 @@ public class BagInit extends BaseEntity { @Column(name = "bag_quantity") private Integer bagQuantity; - @Column(name = "image_url", length = 1000) - private String imageUrl; - @OneToMany(mappedBy = "bagInit", cascade = CascadeType.ALL) private List bagInitStateList; - @OneToOne(mappedBy = "bagInit", cascade = CascadeType.ALL) - private BagCollect bagCollect; - - @Enumerated(EnumType.STRING) - private ClothingSalesStateType clothingSalesState; // 옷장 정리 상태 (관리자용) - - @Column(name = "clothing_sales_count") - private Integer clothingSalesCount; - - @Column(name = "point") - private Long point; - - @Column(name = "weight") - private Double weight; + @OneToMany(mappedBy = "bagInit", cascade = CascadeType.ALL) + private List bagCollect; @Builder - public BagInit(User user, Address address, Integer bagQuantity, String imageUrl, ClothingSalesStateType clothingSalesState, Integer clothingSalesCount, Long point, Double weight) { + public BagInit(User user, Address address, Integer bagQuantity) { this.user = user; this.address = address; this.bagQuantity = bagQuantity; - this.imageUrl = imageUrl; - this.clothingSalesState = clothingSalesState; - this.clothingSalesCount = clothingSalesCount; - this.point = point; - this.weight = weight; - } - - public void updateImageUrl(String imageUrl) { - this.imageUrl = imageUrl; - } - - public void updateClothingSalesState(ClothingSalesStateType clothingSalesState) { - this.clothingSalesState = clothingSalesState; } - - public void updatePoint(long point) { - this.point = point; - } - public void updateWeight(double weight) { - this.weight = weight; - } - } diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/BagInitStateType.java b/src/main/java/com/example/repick/domain/clothingSales/entity/BagInitStateType.java index f9bad860..24508e95 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/entity/BagInitStateType.java +++ b/src/main/java/com/example/repick/domain/clothingSales/entity/BagInitStateType.java @@ -2,59 +2,40 @@ import com.example.repick.global.error.exception.CustomException; import com.example.repick.global.error.exception.ErrorCode; +import lombok.Getter; +@Getter public enum BagInitStateType { - PENDING(1, "신청완료"), - DELIVERING(2, "배송중"), - DELIVERED(3, "배송완료"), - CANCELED(4, "요청취소"); + PENDING(1, "신청 완료", "리픽백 신청"), + DELIVERING(2, "배송 중", "리픽백 배송"), + DELIVERED(3, "배송 완료", "리픽백 배송 완료"), + CANCELED(4, "요청 취소", "요청 취소"); private final int id; - private final String value; + private final String sellerValue; + private final String adminValue; - BagInitStateType(int id, String value) { + BagInitStateType(int id, String sellerValue, String adminValue) { this.id = id; - this.value = value; + this.sellerValue = sellerValue; + this.adminValue = adminValue; } - public int getId() { - return id; - } - - public String getValue() { - return value; - } - - public static BagInitStateType fromId(int id) { + public static BagInitStateType fromSellerValue(String keyword) { for (BagInitStateType bagInitStateType : values()) { - if (bagInitStateType.getId() == id) { + if (bagInitStateType.getSellerValue().equals(keyword)) { return bagInitStateType; } } - throw new CustomException(ErrorCode.INVALID_BAG_INIT_STATUS_ID); + throw new CustomException(ErrorCode.INVALID_BAG_INIT_STATUS_NAME); } - public static BagInitStateType fromValue(String keyword) { + public static BagInitStateType fromAdminValue(String keyword) { for (BagInitStateType bagInitStateType : values()) { - if (bagInitStateType.getValue().equals(keyword)) { + if (bagInitStateType.getAdminValue().equals(keyword)) { return bagInitStateType; } } throw new CustomException(ErrorCode.INVALID_BAG_INIT_STATUS_NAME); } - - public static BagInitStateType fromClothingSalesStateType(ClothingSalesStateType clothingSalesStateType) { - switch (clothingSalesStateType) { - case BAG_DELIVERY -> { - return BagInitStateType.DELIVERING; - } - case BAG_DELIVERED -> { - return BagInitStateType.DELIVERED; - } - case REQUEST_CANCELLED -> { - return BagInitStateType.CANCELED; - } - } - throw new CustomException(ErrorCode.INVALID_BAG_INIT_STATUS_NAME); - } } diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollect.java b/src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollect.java index 7340e8eb..10a8544f 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollect.java +++ b/src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollect.java @@ -5,75 +5,13 @@ import com.example.repick.global.entity.BaseEntity; import jakarta.persistence.*; import lombok.*; +import lombok.experimental.SuperBuilder; import java.time.LocalDate; import java.util.List; @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class BoxCollect extends BaseEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id") - private User user; - - @Embedded - private Address address; - - @Column(name = "box_quantity") - private Integer boxQuantity; - - @Column(name = "image_url", length = 1000) - private String imageUrl; - - @Column(name = "collection_date") - private LocalDate collectionDate; - - @OneToMany(mappedBy = "boxCollect", cascade = CascadeType.ALL) - private List boxCollectStateList; - - @Enumerated(EnumType.STRING) - private ClothingSalesStateType clothingSalesState; // 옷장 정리 상태 (관리자용) - - @Column(name = "clothing_sales_count") - private Integer clothingSalesCount; - - @Column(name = "point") - private Long point; - @Column(name = "weight") - private Double weight; - - @Builder - public BoxCollect(User user, Address address, Integer boxQuantity, String imageUrl, LocalDate collectionDate, ClothingSalesStateType clothingSalesState, Integer clothingSalesCount, Long point, Double weight) { - this.user = user; - this.address = address; - this.boxQuantity = boxQuantity; - this.imageUrl = imageUrl; - this.collectionDate = collectionDate; - this.clothingSalesState = clothingSalesState; - this.clothingSalesCount = clothingSalesCount; - this.point = point; - this.weight = weight; - } - - public void updateImageUrl(String imageUrl) { - this.imageUrl = imageUrl; - } - - public void updateClothingSalesState(ClothingSalesStateType clothingSalesState) { - this.clothingSalesState = clothingSalesState; - } - - public void updatePoint(long point) { - this.point = point; - } - public void updateWeight(double weight) { - this.weight = weight; - } - +@SuperBuilder +public class BoxCollect extends ClothingSales { } diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollectState.java b/src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollectState.java deleted file mode 100644 index 6f65c64d..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollectState.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.example.repick.domain.clothingSales.entity; - -import com.example.repick.global.entity.BaseEntity; -import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class BoxCollectState extends BaseEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Enumerated(EnumType.STRING) - private BoxCollectStateType boxCollectStateType; - - @ManyToOne - @JoinColumn(name = "box_collect_id") - private BoxCollect boxCollect; - - @Builder - public BoxCollectState(BoxCollectStateType boxCollectStateType, BoxCollect boxCollect) { - this.boxCollectStateType = boxCollectStateType; - this.boxCollect = boxCollect; - } - - public static BoxCollectState of(BoxCollectStateType boxCollectStateType, BoxCollect boxCollect) { - return BoxCollectState.builder() - .boxCollectStateType(boxCollectStateType) - .boxCollect(boxCollect) - .build(); - } - -} \ No newline at end of file diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollectStateType.java b/src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollectStateType.java deleted file mode 100644 index 8d77c663..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/entity/BoxCollectStateType.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.example.repick.domain.clothingSales.entity; - -import com.example.repick.global.error.exception.CustomException; -import com.example.repick.global.error.exception.ErrorCode; - -public enum BoxCollectStateType { - PENDING(1, "신청완료"), - DELIVERING(2, "수거중"), - DELIVERED(3, "수거완료"), - INSPECTION_COMPLETED(4, "검수완료"), - SELLING(5, "판매진행"), - CANCELED(6, "요청취소"); - - private final int id; - private final String value; - - BoxCollectStateType(int id, String value) { - this.id = id; - this.value = value; - } - - public int getId() { - return id; - } - - public String getValue() { - return value; - } - - public static BoxCollectStateType fromId(int id) { - for (BoxCollectStateType boxCollectStateType : values()) { - if (boxCollectStateType.getId() == id) { - return boxCollectStateType; - } - } - throw new CustomException(ErrorCode.INVALID_BOX_COLLECT_STATUS_ID); - } - - public static BoxCollectStateType fromValue(String keyword) { - for (BoxCollectStateType boxCollectStateType : values()) { - if (boxCollectStateType.getValue().equals(keyword)) { - return boxCollectStateType; - } - } - throw new CustomException(ErrorCode.INVALID_BOX_COLLECT_STATUS_NAME); - } - - public static BoxCollectStateType fromClothingSalesStateType(ClothingSalesStateType clothingSalesStateType) { - switch (clothingSalesStateType) { - case COLLECTING -> { - return BoxCollectStateType.DELIVERING; - } - case COLLECTED -> { - return BoxCollectStateType.DELIVERED; - } - case REQUEST_CANCELLED -> { - return BoxCollectStateType.CANCELED; - } - case SHOOTING, SHOOTED, PRODUCTING, PRODUCTED -> { - return null; - } - case PRODUCT_REGISTERED -> { - return BoxCollectStateType.INSPECTION_COMPLETED; - } - default -> { - throw new CustomException(ErrorCode.INVALID_CLOTHING_SALES_STATE_NAME); - } - } - } -} 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 new file mode 100644 index 00000000..3cd7f449 --- /dev/null +++ b/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSales.java @@ -0,0 +1,91 @@ +package com.example.repick.domain.clothingSales.entity; + +import com.example.repick.domain.product.entity.Product; +import com.example.repick.domain.user.entity.User; +import com.example.repick.global.entity.Address; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Inheritance(strategy = InheritanceType.JOINED) +@EntityListeners(AuditingEntityListener.class) +@SuperBuilder +public abstract class ClothingSales { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @Column(name = "quantity") + private Integer quantity; + + @Embedded + private Address address; + + @Column(name = "clothing_sales_count") + private Integer clothingSalesCount; + + @Column(name = "point") + private Long point; + + @Column(name = "weight") + private Double weight; + + @Column(name = "image_url", length = 1000) + private String imageUrl; + + @Column(name = "collection_date") + private LocalDate collectionDate; + + private ClothingSalesStateType clothingSalesState; + + @OneToMany(mappedBy = "clothingSales") + private List productList; + + @CreatedDate + @Column(updatable = false) + private LocalDateTime createdDate; + + @LastModifiedDate + private LocalDateTime lastModifiedDate; + + private boolean isDeleted; // default = false + + public void delete() { + this.isDeleted = true; + } + + public void updateImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public void updatePoint(long point) { + this.point = point; + } + public void updateWeight(double weight) { + this.weight = weight; + } + + public void updateClothingSalesState(ClothingSalesStateType clothingSalesState) { + this.clothingSalesState = clothingSalesState; + } + +} diff --git a/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSalesState.java b/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSalesState.java new file mode 100644 index 00000000..6696ff09 --- /dev/null +++ b/src/main/java/com/example/repick/domain/clothingSales/entity/ClothingSalesState.java @@ -0,0 +1,33 @@ +package com.example.repick.domain.clothingSales.entity; + +import com.example.repick.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ClothingSalesState extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private Long clothingSalesId; + @Enumerated(EnumType.STRING) + private ClothingSalesStateType clothingSalesStateType; + + @Builder + public ClothingSalesState(ClothingSalesStateType clothingSalesStateType, Long clothingSalesId) { + this.clothingSalesStateType = clothingSalesStateType; + this.clothingSalesId = clothingSalesId; + } + + public static ClothingSalesState of(Long clothingSalesId, ClothingSalesStateType clothingSalesStateType) { + return ClothingSalesState.builder() + .clothingSalesId(clothingSalesId) + .clothingSalesStateType(clothingSalesStateType) + .build(); + } +} 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 f883fe9f..8d4c8176 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 @@ -4,37 +4,52 @@ import com.example.repick.global.error.exception.ErrorCode; import lombok.Getter; +import java.util.Arrays; +import java.util.List; + @Getter public enum ClothingSalesStateType { - // 관리자(Admin)용 옷장 정리 상태 - // 주의) 유저용 상태와 일관되게 관리 - BOX_REQUEST(1, "박스 신청"), - BAG_REQUEST(2, "리픽백 신청"), - REQUEST_CANCELLED(3, "요청 취소"), - BAG_DELIVERY(4, "리픽백 배송"), - BAG_DELIVERED(5, "리픽백 배송 완료"), - BAG_COLLECT_REQUEST(6, "리픽백 수거 요청"), - COLLECTING(7, "수거 중"), - COLLECTED(8, "수거 완료(푸시)"), - SHOOTING(9, "촬영 중"), - SHOOTED(10, "촬영 완료"), - PRODUCTING(11, "상품화 중"), - PRODUCTED(12, "상품화 완료"), - PRODUCT_REGISTERED(13, "상품 등록 완료"), - SELLING(14, "판매 중"), - SELLING_EXPIRED(15, "판매 기간 만료"); + BOX_COLLECT_REQUEST(1, "신청 완료", "박스 신청"), + BAG_REQUEST(2, "신청 완료", "리픽백 신청"), + REQUEST_CANCELLED(3,"요청 취소", "요청 취소"), + BAG_DELIVERY(4, "배송 중", "리픽백 배송"), + BAG_DELIVERED(5, "배송 완료", "리픽백 배송 완료"), + BAG_COLLECT_REQUEST(6, "신청 완료", "리픽백 신청"), + COLLECTING(7, "수거 중", "수거 중"), + COLLECTED(8, "수거 완료", "수거 완료(푸시)"), + SHOOTING(9, "수거 완료", "촬영 중"), + SHOOTED(10, "수거 완료", "촬영 완료"), + PRODUCTING(11, "수거 완료", "상품화 중"), + PRODUCTED(12, "수거 완료", "상품화 완료"), + PRODUCT_REGISTERED(13, "검수 완료","상품 등록 완료"), + SELLING(14, "판매 진행","판매 중"), + SELLING_EXPIRED(15, "판매 기간 만료", "판매 기간 만료"); private final int id; - private final String value; + private final String sellerValue; + private final String adminValue; + + public static final List AFTER_PRODUCTION = Arrays.asList(PRODUCT_REGISTERED, SELLING, SELLING_EXPIRED); + public static final List AFTER_SELLING = Arrays.asList(SELLING, SELLING_EXPIRED); - ClothingSalesStateType(int id, String value) { + ClothingSalesStateType(int id, String sellerValue, String adminValue) { this.id = id; - this.value = value; + this.sellerValue = sellerValue; + this.adminValue = adminValue; + } + + public static ClothingSalesStateType fromSellerValue(String keyword){ + for (ClothingSalesStateType clothingSalesStateType : values()) { + if (clothingSalesStateType.getSellerValue().equals(keyword)) { + return clothingSalesStateType; + } + } + throw new CustomException(ErrorCode.INVALID_CLOTHING_SALES_STATE_NAME); } - public static ClothingSalesStateType fromValue(String keyword){ + public static ClothingSalesStateType fromAdminValue(String keyword){ for (ClothingSalesStateType clothingSalesStateType : values()) { - if (clothingSalesStateType.getValue().equals(keyword)) { + if (clothingSalesStateType.getAdminValue().equals(keyword)) { return clothingSalesStateType; } } diff --git a/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepository.java b/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepository.java index b397d6eb..f4ecb38c 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepository.java +++ b/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepository.java @@ -3,8 +3,5 @@ import com.example.repick.domain.clothingSales.entity.BagCollect; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.Optional; - -public interface BagCollectRepository extends JpaRepository, BagCollectRepositoryCustom { - Optional findByBagInitId(Long bagInitId); +public interface BagCollectRepository extends JpaRepository { } \ No newline at end of file diff --git a/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepositoryCustom.java b/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepositoryCustom.java deleted file mode 100644 index 6bd94c21..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepositoryCustom.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.example.repick.domain.clothingSales.repository; - -public interface BagCollectRepositoryCustom { -} diff --git a/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepositoryImpl.java b/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepositoryImpl.java deleted file mode 100644 index e4749bfa..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectRepositoryImpl.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.example.repick.domain.clothingSales.repository; - -import com.querydsl.jpa.impl.JPAQueryFactory; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -public class BagCollectRepositoryImpl implements BagCollectRepositoryCustom { - - private final JPAQueryFactory jpaQueryFactory; - - - -} diff --git a/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectStateRepository.java b/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectStateRepository.java deleted file mode 100644 index ff9cd0c2..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/repository/BagCollectStateRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.example.repick.domain.clothingSales.repository; - -import com.example.repick.domain.clothingSales.entity.BagCollectState; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface BagCollectStateRepository extends JpaRepository { -} diff --git a/src/main/java/com/example/repick/domain/clothingSales/repository/BagInitRepository.java b/src/main/java/com/example/repick/domain/clothingSales/repository/BagInitRepository.java index b2a44397..1ad25320 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/repository/BagInitRepository.java +++ b/src/main/java/com/example/repick/domain/clothingSales/repository/BagInitRepository.java @@ -3,12 +3,6 @@ import com.example.repick.domain.clothingSales.entity.BagInit; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.List; -import java.util.Optional; public interface BagInitRepository extends JpaRepository { - List findByUserId(Long userId); - Integer countByUserId(Long userId); - - Optional findByUserIdAndClothingSalesCount(Long userId, Integer clothingSalesCount); } \ No newline at end of file diff --git a/src/main/java/com/example/repick/domain/clothingSales/repository/BagInitStateRepository.java b/src/main/java/com/example/repick/domain/clothingSales/repository/BagInitStateRepository.java index 9e51f494..e8fd0c48 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/repository/BagInitStateRepository.java +++ b/src/main/java/com/example/repick/domain/clothingSales/repository/BagInitStateRepository.java @@ -1,9 +1,14 @@ package com.example.repick.domain.clothingSales.repository; +import com.example.repick.domain.clothingSales.entity.BagInit; import com.example.repick.domain.clothingSales.entity.BagInitState; import com.example.repick.domain.clothingSales.entity.BagInitStateType; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface BagInitStateRepository extends JpaRepository { boolean existsByBagInitIdAndBagInitStateType(Long id, BagInitStateType delivered); + + Optional findFirstByBagInitOrderByCreatedDateDesc(BagInit bagInit); } diff --git a/src/main/java/com/example/repick/domain/clothingSales/repository/BoxCollectRepository.java b/src/main/java/com/example/repick/domain/clothingSales/repository/BoxCollectRepository.java index 2fbcf33a..be7eb1d5 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/repository/BoxCollectRepository.java +++ b/src/main/java/com/example/repick/domain/clothingSales/repository/BoxCollectRepository.java @@ -3,13 +3,6 @@ import com.example.repick.domain.clothingSales.entity.BoxCollect; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.List; -import java.util.Optional; public interface BoxCollectRepository extends JpaRepository { - List findByUserId(Long userId); - - Integer countByUserId(Long userId); - - Optional findByUserIdAndClothingSalesCount(Long userId, Integer clothingSalesCount); } \ No newline at end of file diff --git a/src/main/java/com/example/repick/domain/clothingSales/repository/BoxCollectStateRepository.java b/src/main/java/com/example/repick/domain/clothingSales/repository/BoxCollectStateRepository.java deleted file mode 100644 index f2809046..00000000 --- a/src/main/java/com/example/repick/domain/clothingSales/repository/BoxCollectStateRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.example.repick.domain.clothingSales.repository; - -import com.example.repick.domain.clothingSales.entity.BoxCollectState; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface BoxCollectStateRepository extends JpaRepository { -} 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 new file mode 100644 index 00000000..fe8eb7c5 --- /dev/null +++ b/src/main/java/com/example/repick/domain/clothingSales/repository/ClothingSalesRepository.java @@ -0,0 +1,16 @@ +package com.example.repick.domain.clothingSales.repository; + +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.jpa.repository.JpaRepository; + +import java.util.List; +import java.util.Optional; + +public interface ClothingSalesRepository extends JpaRepository { + List findByUserAndClothingSalesState(User user, ClothingSalesStateType clothingSalesStateType); + List findByUserOrderByCreatedDateDesc(User user); + Optional findByUserAndClothingSalesCount(User user, Integer clothingSalesCount); + int countByUser(User user); +} diff --git a/src/main/java/com/example/repick/domain/clothingSales/repository/ClothingSalesStateRepository.java b/src/main/java/com/example/repick/domain/clothingSales/repository/ClothingSalesStateRepository.java new file mode 100644 index 00000000..44e3cf8b --- /dev/null +++ b/src/main/java/com/example/repick/domain/clothingSales/repository/ClothingSalesStateRepository.java @@ -0,0 +1,10 @@ +package com.example.repick.domain.clothingSales.repository; + +import com.example.repick.domain.clothingSales.entity.ClothingSalesState; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ClothingSalesStateRepository extends JpaRepository{ + List findByClothingSalesId(Long clothingSalesId); +} 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 f6fcc2b1..01e176c1 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 @@ -17,8 +17,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - import static com.example.repick.global.error.exception.ErrorCode.INVALID_BAG_INIT_ID; @Service @RequiredArgsConstructor @@ -28,33 +26,23 @@ public class BagService { private final BagInitRepository bagInitRepository; private final BagInitStateRepository bagInitStateRepository; private final BagCollectRepository bagCollectRepository; - private final BagCollectStateRepository bagCollectStateRepository; - private final ClothingSalesValidator clothingSalesValidator; private final S3UploadService s3UploadService; - private final BoxCollectRepository boxCollectRepository; + private final ClothingSalesRepository clothingSalesRepository; + private final ClothingSalesStateRepository clothingSalesStateRepository; @Transactional public BagInitResponse registerBagInit(PostBagInit postBagInit) { User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName()) .orElseThrow(() -> new UsernameNotFoundException("사용자를 찾을 수 없습니다.")); - - - // Count the number of the clothingSalesCount of the user - Integer bagInitCount = bagInitRepository.countByUserId(user.getId()); - Integer boxCollectCount = boxCollectRepository.countByUserId(user.getId()); - // BagInit - BagInit bagInit = postBagInit.toEntity(user, bagInitCount + boxCollectCount + 1); - - bagInit.updateImageUrl(s3UploadService.saveFile(postBagInit.image(), "clothingSales/bagInit/" + user.getId() + "/" + bagInit.getId())); - + BagInit bagInit = postBagInit.toEntity(user); bagInitRepository.save(bagInit); // BagInitState BagInitState bagInitState = BagInitState.of(BagInitStateType.PENDING, bagInit); bagInitStateRepository.save(bagInitState); - return BagInitResponse.of(bagInit, bagInitState.getBagInitStateType().getValue()); + return BagInitResponse.of(bagInit, bagInitState.getBagInitStateType().getSellerValue()); } @@ -66,34 +54,27 @@ public BagCollectResponse registerBagCollect(PostBagCollect postBagCollect) { BagInit bagInit = bagInitRepository.findById(postBagCollect.bagInitId()) .orElseThrow(() -> new CustomException(INVALID_BAG_INIT_ID)); + if(!bagInit.getUser().getId().equals(user.getId())) { + throw new CustomException(INVALID_BAG_INIT_ID); + } + // 만약 bagInit의 state에 배송완료가 없다면 자동으로 추가한다. if (!bagInitStateRepository.existsByBagInitIdAndBagInitStateType(bagInit.getId(), BagInitStateType.DELIVERED)) { BagInitState bagInitState = BagInitState.of(BagInitStateType.DELIVERED, bagInit); bagInitStateRepository.save(bagInitState); } - // Validations - clothingSalesValidator.userBagInitMatches(user.getId(), bagInit); - clothingSalesValidator.duplicateBagCollectExists(bagInit.getId()); - // BagCollect - BagCollect bagCollect = postBagCollect.toEntity(bagInit, user); - + BagCollect bagCollect = postBagCollect.toEntity(bagInit, user, clothingSalesRepository.countByUser(user) + 1); bagCollect.updateImageUrl(s3UploadService.saveFile(postBagCollect.image(), "clothingSales/bagCollect/" + user.getId() + "/" + bagCollect.getId())); - bagCollectRepository.save(bagCollect); // BagCollectState - BagCollectState bagCollectState = BagCollectState.of(BagCollectStateType.PENDING, bagCollect); - bagCollectStateRepository.save(bagCollectState); - bagInit.updateClothingSalesState(ClothingSalesStateType.BAG_COLLECT_REQUEST); - - return BagCollectResponse.of(bagCollect, bagCollectState.getBagCollectStateType().getValue()); + ClothingSalesState clothingSalesState = ClothingSalesState.of(bagCollect.getId(), ClothingSalesStateType.BAG_COLLECT_REQUEST); + clothingSalesStateRepository.save(clothingSalesState); - } + return BagCollectResponse.of(bagCollect, clothingSalesState.getClothingSalesStateType().getSellerValue()); - public List getBagInitByUser(Long userId) { - return bagInitRepository.findByUserId(userId); } } diff --git a/src/main/java/com/example/repick/domain/clothingSales/service/BoxService.java b/src/main/java/com/example/repick/domain/clothingSales/service/BoxService.java index bd4c6dfd..68fe56ab 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/service/BoxService.java +++ b/src/main/java/com/example/repick/domain/clothingSales/service/BoxService.java @@ -2,11 +2,11 @@ import com.example.repick.domain.clothingSales.dto.*; import com.example.repick.domain.clothingSales.entity.BoxCollect; -import com.example.repick.domain.clothingSales.entity.BoxCollectState; -import com.example.repick.domain.clothingSales.entity.BoxCollectStateType; -import com.example.repick.domain.clothingSales.repository.BagInitRepository; +import com.example.repick.domain.clothingSales.entity.ClothingSalesState; +import com.example.repick.domain.clothingSales.entity.ClothingSalesStateType; import com.example.repick.domain.clothingSales.repository.BoxCollectRepository; -import com.example.repick.domain.clothingSales.repository.BoxCollectStateRepository; +import com.example.repick.domain.clothingSales.repository.ClothingSalesRepository; +import com.example.repick.domain.clothingSales.repository.ClothingSalesStateRepository; import com.example.repick.domain.user.entity.User; import com.example.repick.domain.user.repository.UserRepository; import com.example.repick.global.aws.S3UploadService; @@ -16,7 +16,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; import static com.example.repick.global.error.exception.ErrorCode.USER_NOT_FOUND; @@ -25,38 +24,24 @@ public class BoxService { private final UserRepository userRepository; private final BoxCollectRepository boxCollectRepository; - private final BoxCollectStateRepository boxCollectStateRepository; private final S3UploadService s3UploadService; - private final BagInitRepository bagInitRepository; - + private final ClothingSalesRepository clothingSalesRepository; + private final ClothingSalesStateRepository clothingSalesStateRepository; @Transactional public BoxCollectResponse registerBoxCollect(PostBoxCollect postBoxCollect) { User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName()) .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); - - // Count the number of the clothingSalesCount of the user - Integer bagInitCount = bagInitRepository.countByUserId(user.getId()); - Integer boxCollectCount = boxCollectRepository.countByUserId(user.getId()); - - // BoxCollect - BoxCollect boxCollect = postBoxCollect.toEntity(user, bagInitCount + boxCollectCount + 1); - + BoxCollect boxCollect = postBoxCollect.toEntity(user, clothingSalesRepository.countByUser(user) + 1); boxCollect.updateImageUrl(s3UploadService.saveFile(postBoxCollect.image(), "clothingSales/boxCollect/" + user.getId() + "/" + boxCollect.getId())); - boxCollectRepository.save(boxCollect); // BoxCollectState - BoxCollectState boxCollectState = BoxCollectState.of(BoxCollectStateType.PENDING, boxCollect); - - boxCollectStateRepository.save(boxCollectState); + ClothingSalesState clothingSalesState = ClothingSalesState.of(boxCollect.getId(), ClothingSalesStateType.BOX_COLLECT_REQUEST); + clothingSalesStateRepository.save(clothingSalesState); - return BoxCollectResponse.of(boxCollect, boxCollectState.getBoxCollectStateType().getValue()); - - } + return BoxCollectResponse.of(boxCollect, clothingSalesState.getClothingSalesStateType().getSellerValue()); - public List getBoxCollectByUser(Long userId) { - return boxCollectRepository.findByUserId(userId); } } 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 e75bc72c..d9a4738d 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 @@ -5,8 +5,10 @@ import com.example.repick.domain.clothingSales.repository.*; import com.example.repick.domain.clothingSales.validator.ClothingSalesValidator; import com.example.repick.domain.product.entity.Product; +import com.example.repick.domain.product.entity.ProductOrder; import com.example.repick.domain.product.entity.ProductState; import com.example.repick.domain.product.entity.ProductStateType; +import com.example.repick.domain.product.repository.ProductOrderRepository; import com.example.repick.domain.product.repository.ProductRepository; import com.example.repick.domain.product.repository.ProductStateRepository; import com.example.repick.domain.product.service.ProductService; @@ -23,134 +25,59 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.concurrent.atomic.AtomicReference; import static com.example.repick.global.error.exception.ErrorCode.*; +@Transactional(readOnly = true) @Service @RequiredArgsConstructor public class ClothingSalesService { private final UserRepository userRepository; - private final BagService bagService; - private final BoxService boxService; private final ProductService productService; private final BagInitRepository bagInitRepository; - private final BoxCollectRepository boxCollectRepository; + private final BagInitStateRepository bagInitStateRepository; private final ClothingSalesValidator clothingSalesValidator; private final ProductRepository productRepository; private final ProductStateRepository productStateRepository; - private final BoxCollectStateRepository boxCollectStateRepository; - private final BagInitStateRepository bagInitStateRepository; - private final BagCollectStateRepository bagCollectStateRepository; - - public Boolean getIsBoxCollect(long userId, int clothingSalesCount) { - return boxCollectRepository.findByUserIdAndClothingSalesCount(userId, clothingSalesCount).isPresent(); - } + private final ClothingSalesRepository clothingSalesRepository; + private final ClothingSalesStateRepository clothingSalesStateRepository; + private final ProductOrderRepository productOrderRepository; public void updateSellingExpired(Product product) { - if(getIsBoxCollect(product.getUser().getId(), product.getClothingSalesCount())){ - BoxCollect boxCollect = boxCollectRepository.findByUserIdAndClothingSalesCount(product.getUser().getId(), product.getClothingSalesCount()) - .orElseThrow(() -> new CustomException(INVALID_BOX_COLLECT_ID)); - boxCollect.updateClothingSalesState(ClothingSalesStateType.SELLING_EXPIRED); - boxCollectRepository.save(boxCollect); - } - else{ - BagInit bagInit = bagInitRepository.findByUserIdAndClothingSalesCount(product.getUser().getId(), product.getClothingSalesCount()) - .orElseThrow(() -> new CustomException(INVALID_BAG_INIT_ID)); - bagInit.updateClothingSalesState(ClothingSalesStateType.SELLING_EXPIRED); - bagInitRepository.save(bagInit); - } + ClothingSalesState clothingSalesState = ClothingSalesState.of(product.getClothingSales().getId(), ClothingSalesStateType.SELLING_EXPIRED); + clothingSalesStateRepository.save(clothingSalesState); } public List getPendingClothingSales() { User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName()) .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); - List clothingSalesList = new ArrayList<>(); - - AtomicReference isCanceledOrCompleted = new AtomicReference<>(false); - - AtomicReference requestDate = new AtomicReference<>(); - AtomicReference bagArriveDate = new AtomicReference<>(); - AtomicReference collectDate = new AtomicReference<>(); - AtomicReference productDate = new AtomicReference<>(); - - // get bag inits - bagService.getBagInitByUser(user.getId()).forEach(bagInit -> { - requestDate.set(null); - bagArriveDate.set(null); - collectDate.set(null); - productDate.set(null); - isCanceledOrCompleted.set(false); - - bagInit.getBagInitStateList().forEach(bagInitState -> { - if (bagInitState.getBagInitStateType().equals(BagInitStateType.PENDING)) { - requestDate.set(bagInitState.getCreatedDate().format(DateTimeFormatter.ofPattern("yy.MM.dd"))); - } else if (bagInitState.getBagInitStateType().equals(BagInitStateType.DELIVERED)) { - bagArriveDate.set(bagInitState.getCreatedDate().format(DateTimeFormatter.ofPattern("yy.MM.dd"))); - - // if bagInit is delivered, get bag collects - bagInit.getBagCollect().getBagCollectStateList().forEach(bagCollectState -> { - if (bagCollectState.getBagCollectStateType().equals(BagCollectStateType.DELIVERED)) { - collectDate.set(bagCollectState.getCreatedDate().format(DateTimeFormatter.ofPattern("yy.MM.dd"))); - } else if (bagCollectState.getBagCollectStateType().equals(BagCollectStateType.INSPECTION_COMPLETED)) { - productDate.set(bagCollectState.getCreatedDate().format(DateTimeFormatter.ofPattern("yy.MM.dd"))); - } else if (bagCollectState.getBagCollectStateType().equals(BagCollectStateType.CANCELED)) { - isCanceledOrCompleted.set(true); - } else if (bagCollectState.getBagCollectStateType().equals(BagCollectStateType.SELLING)) { - isCanceledOrCompleted.set(true); - } - }); - } else if (bagInitState.getBagInitStateType().equals(BagInitStateType.CANCELED)) { - isCanceledOrCompleted.set(true); - } - }); - - if (!isCanceledOrCompleted.get()) - clothingSalesList.add(GetPendingClothingSales.of(bagInit.getId(), bagInit.getClothingSalesCount(), "백", requestDate.get(), bagArriveDate.get(), collectDate.get(), productDate.get())); - }); - - - // get box collects - boxService.getBoxCollectByUser(user.getId()).forEach(boxCollect -> { - requestDate.set(null); - collectDate.set(null); - productDate.set(null); - isCanceledOrCompleted.set(false); - - boxCollect.getBoxCollectStateList().forEach(boxCollectState -> { - if (boxCollectState.getBoxCollectStateType().equals(BoxCollectStateType.PENDING)) { - requestDate.set(boxCollectState.getCreatedDate().format(DateTimeFormatter.ofPattern("yy.MM.dd"))); - } else if (boxCollectState.getBoxCollectStateType().equals(BoxCollectStateType.DELIVERED)) { - collectDate.set(boxCollectState.getCreatedDate().format(DateTimeFormatter.ofPattern("yy.MM.dd"))); - } else if (boxCollectState.getBoxCollectStateType().equals(BoxCollectStateType.INSPECTION_COMPLETED)) { - productDate.set(boxCollectState.getCreatedDate().format(DateTimeFormatter.ofPattern("yy.MM.dd"))); - } else if (boxCollectState.getBoxCollectStateType().equals(BoxCollectStateType.CANCELED)) { - isCanceledOrCompleted.set(true); - } else if (boxCollectState.getBoxCollectStateType().equals(BoxCollectStateType.SELLING)) { - isCanceledOrCompleted.set(true); + List pendingClothingSalesList = new ArrayList<>(); + List clothingSalesList = clothingSalesRepository.findByUserOrderByCreatedDateDesc(user); + clothingSalesList.forEach(clothingSales -> { + List clothingSalesStateList = clothingSalesStateRepository.findByClothingSalesId(clothingSales.getId()); + LocalDateTime requestDate = null; + LocalDateTime collectDate = null; + LocalDateTime shootDate = null; + LocalDateTime productDate = null; + for (ClothingSalesState clothingSalesState : clothingSalesStateList) { + switch (clothingSalesState.getClothingSalesStateType()) { + case BOX_COLLECT_REQUEST, BAG_COLLECT_REQUEST -> requestDate = clothingSalesState.getCreatedDate(); + case COLLECTED -> collectDate = clothingSalesState.getCreatedDate(); + case SHOOTED -> shootDate = clothingSalesState.getCreatedDate(); + case PRODUCT_REGISTERED -> productDate = clothingSalesState.getCreatedDate(); } - }); - - if (!isCanceledOrCompleted.get()) - clothingSalesList.add(GetPendingClothingSales.of(boxCollect.getId(), boxCollect.getClothingSalesCount(), "박스", requestDate.get(), null, collectDate.get(), productDate.get())); - }); - - // order by created date - clothingSalesList.sort((o1, o2) -> { - if (o1.requestDate().equals(o2.requestDate())) { - return 0; } - return o1.requestDate().compareTo(o2.requestDate()); + pendingClothingSalesList.add(GetPendingClothingSales.of(clothingSales, requestDate, collectDate, shootDate, productDate)); }); - - return clothingSalesList; - + return pendingClothingSalesList; } @Transactional @@ -176,22 +103,13 @@ public Boolean updateProductPrice(List postProductPriceList) { }); productRepository.saveAll(productList); - Optional bagInit = bagInitRepository.findByUserIdAndClothingSalesCount(user.getId(), productList.get(0).getClothingSalesCount()); - if(bagInit.isPresent()){ - BagCollectState bagCollectState = BagCollectState.of(BagCollectStateType.SELLING, bagInit.get().getBagCollect()); - bagCollectStateRepository.save(bagCollectState); - bagInit.get().updateClothingSalesState(ClothingSalesStateType.SELLING); - return true; - } + ClothingSales clothingSales = productList.get(0).getClothingSales(); + ClothingSalesState clothingSalesState = ClothingSalesState.of(clothingSales.getId(), ClothingSalesStateType.SELLING); + clothingSalesStateRepository.save(clothingSalesState); + clothingSales.updateClothingSalesState(ClothingSalesStateType.SELLING); + clothingSalesRepository.save(clothingSales); - Optional boxCollect = boxCollectRepository.findByUserIdAndClothingSalesCount(user.getId(), productList.get(0).getClothingSalesCount()); - if(boxCollect.isPresent()){ - BoxCollectState boxCollectState = BoxCollectState.of(BoxCollectStateType.SELLING, boxCollect.get()); - boxCollectStateRepository.save(boxCollectState); - boxCollect.get().updateClothingSalesState(ClothingSalesStateType.SELLING); - return true; - } - throw new CustomException(INVALID_CLOTHING_SALES); + return true; } public List getSellingClothingSales() { @@ -199,122 +117,48 @@ public List getSellingClothingSales() { .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); List sellingClothingSalesList = new ArrayList<>(); + List clothingSalesList = clothingSalesRepository.findByUserAndClothingSalesState(user, ClothingSalesStateType.SELLING); - List boxCollectList = boxService.getBoxCollectByUser(user.getId()) - // boxCollectStateType이 SELLING인 것만 가져온다. - .stream() - .filter(boxCollect -> boxCollect.getBoxCollectStateList().stream().anyMatch(boxCollectState -> boxCollectState.getBoxCollectStateType().equals(BoxCollectStateType.SELLING))) - .toList(); - - List bagInitList = bagService.getBagInitByUser(user.getId()) - // bagCollectStateType이 SELLING인 것만 가져온다. - .stream() - .filter(bagInit -> bagInit.getBagCollect() != null) - .filter(bagInit -> bagInit.getBagCollect().getBagCollectStateList().stream().anyMatch(bagCollectState -> bagCollectState.getBagCollectStateType().equals(BagCollectStateType.SELLING))) - .toList(); - - boxCollectList.forEach(boxCollect -> { - List productList = productService.findByClothingSales(user.getId(), boxCollect.getClothingSalesCount()); - AtomicReference sellingQuantity = new AtomicReference<>(0); - AtomicReference pendingQuantity = new AtomicReference<>(0); - AtomicReference soldQuantity = new AtomicReference<>(0); - - // 각각 상품들에 연결된 productSellingState 중 가장 id값이 높은 것들에 대해서, - // 상태가 SELLING인 경우 sellingQuantity를 증가시킨다. - // 상태가 SOLD_OUT인 경우, 해당 state의 createdDate가 7일 이후면 soldQuantity를 증가시키고, 7일 이전이면 pendingQuantity를 증가시킨다. - productList.forEach(product -> { - ProductState productState = productStateRepository.findFirstByProductIdOrderByCreatedDateDesc(product.getId()).orElseThrow(() -> new CustomException(INVALID_PRODUCT_ID)); - if (productState.getProductStateType().equals(ProductStateType.SELLING)) { - sellingQuantity.getAndSet(sellingQuantity.get() + 1); - } else if (productState.getProductStateType().equals(ProductStateType.SOLD_OUT)) { - if (productState.getCreatedDate().plusDays(7).isBefore(LocalDateTime.now())) { - soldQuantity.getAndSet(soldQuantity.get() + 1); - } else { - pendingQuantity.getAndSet(pendingQuantity.get() + 1); - } - } - }); - - sellingClothingSalesList.add(new GetSellingClothingSales( - boxCollect.getId(), - boxCollect.getClothingSalesCount(), - boxCollect.getCreatedDate().format(DateTimeFormatter.ofPattern("yy.MM.dd")), - sellingQuantity.get(), - pendingQuantity.get(), - soldQuantity.get(), - boxCollect.getPoint())); - }); - - bagInitList.forEach(bagInit -> { - List productList = productService.findByClothingSales(user.getId(), bagInit.getClothingSalesCount()); - AtomicReference sellingQuantity = new AtomicReference<>(0); - AtomicReference pendingQuantity = new AtomicReference<>(0); - AtomicReference soldQuantity = new AtomicReference<>(0); - - productList.forEach(product -> { - ProductState productState = productStateRepository.findFirstByProductIdOrderByCreatedDateDesc(product.getId()).orElseThrow(() -> new CustomException(INVALID_PRODUCT_ID)); - if (productState.getProductStateType().equals(ProductStateType.SELLING)) { - sellingQuantity.getAndSet(sellingQuantity.get() + 1); - } else if (productState.getProductStateType().equals(ProductStateType.SOLD_OUT)) { - if (productState.getCreatedDate().plusDays(7).isBefore(LocalDateTime.now())) { - soldQuantity.getAndSet(soldQuantity.get() + 1); + for (ClothingSales clothingSales : clothingSalesList) { + List productList = clothingSales.getProductList(); + if(productList.isEmpty()) { + continue; + } + LocalDateTime salesStartDate = productList.get(0).getSalesStartDate(); + int remainingSalesDays = (int) ChronoUnit.DAYS.between(LocalDate.now(), salesStartDate.toLocalDate().plusDays(90)); + int sellingQuantity = 0; + int pendingQuantity = 0; + int soldQuantity = 0; + for (Product product : productList) { + if (product.getProductState().equals(ProductStateType.SELLING)) { + sellingQuantity++; + } else if (product.getProductState().equals(ProductStateType.SOLD_OUT)) { + ProductOrder productOrder = productOrderRepository.findFirstByProductIdOrderByCreatedDateDesc(product.getId()) + .orElseThrow(() -> new CustomException(INVALID_PRODUCT_ID)); + if (productOrder.isConfirmed()) { + soldQuantity++; } else { - pendingQuantity.getAndSet(pendingQuantity.get() + 1); + pendingQuantity++; } } - }); - - sellingClothingSalesList.add(new GetSellingClothingSales( - bagInit.getId(), - bagInit.getClothingSalesCount(), - bagInit.getCreatedDate().format(DateTimeFormatter.ofPattern("yy.MM.dd")), - sellingQuantity.get(), - pendingQuantity.get(), - soldQuantity.get(), - bagInit.getPoint())); - }); - + } + sellingClothingSalesList.add(GetSellingClothingSales.of(clothingSales, salesStartDate.format(DateTimeFormatter.ofPattern("yyyy.MM.dd")), remainingSalesDays, sellingQuantity, pendingQuantity, soldQuantity)); + } return sellingClothingSalesList; } - public GetProductListByClothingSales getProductsByClothingSalesCount(Integer clothingSalesCount) { + public GetProductListByClothingSales getProductsByClothingSalesId(Long clothingSalesId) { User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName()) .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); - - Optional bagInitOptional = bagInitRepository.findByUserIdAndClothingSalesCount(user.getId(), clothingSalesCount); - - if (bagInitOptional.isPresent()) { - BagInit bagInit = bagInitOptional.get(); - - // validate bagInitId and user - clothingSalesValidator.userBagInitMatches(user.getId(), bagInit); - - List getProductByClothingSalesDtoList = productRepository.findProductDtoByUserIdAndClothingSalesCount(user.getId(), clothingSalesCount); - - ProductQuantityCounter productQuantityCounter = countProductQuantity(getProductByClothingSalesDtoList); - - return new GetProductListByClothingSales(getProductByClothingSalesDtoList, bagInit.getBagQuantity(), productQuantityCounter.preparingQuantity(), productQuantityCounter.rejectedQuantity()); + ClothingSales clothingSales = clothingSalesRepository.findById(clothingSalesId) + .orElseThrow(() -> new CustomException(INVALID_CLOTHING_SALES_ID)); + if(!clothingSales.getUser().getId().equals(user.getId())){ + throw new CustomException(INVALID_CLOTHING_SALES_ID); } - - - Optional boxCollectOptional = boxCollectRepository.findByUserIdAndClothingSalesCount(user.getId(), clothingSalesCount); - - if (boxCollectOptional.isPresent()) { - BoxCollect boxCollect = boxCollectOptional.get(); - - // validate boxCollectId and user - clothingSalesValidator.userBoxCollectMatches(user.getId(), boxCollect); - - List getProductByClothingSalesDtoList = productRepository.findProductDtoByUserIdAndClothingSalesCount(user.getId(), clothingSalesCount); - - ProductQuantityCounter productQuantity = countProductQuantity(getProductByClothingSalesDtoList); - - return new GetProductListByClothingSales(getProductByClothingSalesDtoList, boxCollect.getBoxQuantity(), productQuantity.preparingQuantity(), productQuantity.rejectedQuantity()); - } - - throw new CustomException(INVALID_CLOTHING_SALES); - + List getProductByClothingSalesDtoList = productRepository.findProductDtoByClothingSalesId(clothingSalesId); + ProductQuantityCounter productQuantityCounter = countProductQuantity(getProductByClothingSalesDtoList); + return new GetProductListByClothingSales(getProductByClothingSalesDtoList, clothingSales.getQuantity(), productQuantityCounter.preparingQuantity(), productQuantityCounter.rejectedQuantity()); } private ProductQuantityCounter countProductQuantity(List getProductByClothingSalesDtoList) { @@ -333,26 +177,30 @@ private ProductQuantityCounter countProductQuantity(List> getClothingSalesInformation(PageCondition pageCondition){ - List clothingSalesList = new ArrayList<>(bagInitRepository.findAll().stream() - .map(bagInit -> { - List products = productService.findByClothingSales(bagInit.getUser().getId(), bagInit.getClothingSalesCount()); + // 수거 신청 정보 조회 + List clothingSalesList = new ArrayList<>(clothingSalesRepository.findAll().stream() + .map(clothingSales -> { + List products = clothingSales.getProductList(); List productStates = products.stream() .map(product -> productStateRepository.findFirstByProductIdOrderByCreatedDateDesc(product.getId())) .flatMap(Optional::stream) .toList(); - return GetClothingSales.of(bagInit, products, productStates); + return GetClothingSales.ofClothingSales(clothingSales, productStates); }) .toList()); - clothingSalesList.addAll(boxCollectRepository.findAll().stream() - .map(boxCollect -> { - List products = productService.findByClothingSales(boxCollect.getUser().getId(), boxCollect.getClothingSalesCount()); - List productStates = products.stream() - .map(product -> productStateRepository.findFirstByProductIdOrderByCreatedDateDesc(product.getId())) - .flatMap(Optional::stream) - .toList(); - return GetClothingSales.of(boxCollect, products, productStates); + System.out.println(clothingSalesList); + // 리픽백 배송 요청 정보 조회 + List bagInitList = bagInitRepository.findAll().stream() + .map(bagInit -> { + BagInitState bagInitState = bagInitStateRepository.findFirstByBagInitOrderByCreatedDateDesc(bagInit) + .orElseThrow(() -> new CustomException(INVALID_BAG_INIT_ID)); + return GetClothingSales.ofBagInit(bagInit, bagInitState); }) - .toList()); + .toList(); + System.out.println(bagInitList); + clothingSalesList.addAll(bagInitList); + System.out.println(clothingSalesList); + // createdAt 순서로 내림차순 정렬 clothingSalesList.sort((o1, o2) -> o2.requestDate().compareTo(o1.requestDate())); @@ -368,81 +216,57 @@ public PageResponse> getClothingSalesInformation(PageCond @Transactional public Boolean updateClothingSalesState(PostClothingSalesState postClothingSalesState) { - ClothingSalesStateType clothingSalesStateType = ClothingSalesStateType.fromValue(postClothingSalesState.clothingSalesState()); - if (postClothingSalesState.isBoxCollect()) { - // Admin 용 상태 관리 - BoxCollect boxCollect = boxCollectRepository.findByUserIdAndClothingSalesCount(postClothingSalesState.userId(), postClothingSalesState.clothingSalesCount()) - .orElseThrow(() -> new CustomException(INVALID_BOX_COLLECT_ID)); - boxCollect.updateClothingSalesState(clothingSalesStateType); - - // User 용 상태 관리 - BoxCollectStateType boxCollectStateType = BoxCollectStateType.fromClothingSalesStateType(clothingSalesStateType); - if (boxCollectStateType != null) { - BoxCollectState boxCollectState = BoxCollectState.of(boxCollectStateType, boxCollect); - boxCollectStateRepository.save(boxCollectState); - } - } else { - // Admin 용 상태 관리 - BagInit bagInit = bagInitRepository.findByUserIdAndClothingSalesCount(postClothingSalesState.userId(), postClothingSalesState.clothingSalesCount()) + if (postClothingSalesState.isBagDelivered()){ + ClothingSales clothingSales = clothingSalesRepository.findById(postClothingSalesState.id()) + .orElseThrow(() -> new CustomException(INVALID_CLOTHING_SALES_ID)); + + ClothingSalesStateType clothingSalesStateType = ClothingSalesStateType.fromAdminValue(postClothingSalesState.clothingSalesState()); + ClothingSalesState clothingSalesState = ClothingSalesState.of(clothingSales.getId(), clothingSalesStateType); + clothingSalesStateRepository.save(clothingSalesState); + + clothingSales.updateClothingSalesState(clothingSalesStateType); + clothingSalesRepository.save(clothingSales); + } + else{ + BagInit bagInit = bagInitRepository.findById(postClothingSalesState.id()) .orElseThrow(() -> new CustomException(INVALID_BAG_INIT_ID)); - bagInit.updateClothingSalesState(ClothingSalesStateType.fromValue(postClothingSalesState.clothingSalesState())); - - // User 용 상태 관리 - if (postClothingSalesState.isBagDelivered()) { - BagCollect bagCollect = bagInit.getBagCollect(); - BagCollectStateType bagCollectStateType = BagCollectStateType.fromClothingSalesStateType(clothingSalesStateType); - if (bagCollectStateType != null) { - BagCollectState bagCollectState = BagCollectState.of(bagCollectStateType, bagCollect); - bagCollectStateRepository.save(bagCollectState); - } - } else { - BagInitState bagInitState = BagInitState.of(BagInitStateType.fromClothingSalesStateType(clothingSalesStateType), bagInit); - bagInitStateRepository.save(bagInitState); - } + BagInitState.of(BagInitStateType.fromAdminValue(postClothingSalesState.clothingSalesState()), bagInit); + bagInitRepository.save(bagInit); } return true; } + @Transactional public PageResponse> getClothingSalesProductCount(PageCondition pageCondition) { Page pages = productRepository.getClothingSalesProductCount(pageCondition.toPageable()); return PageResponse.of(pages.getContent(), pages.getTotalPages(), pages.getTotalElements()); } - public Boolean updateClothingSalesWeight(PostClothingSalesWeight postClothingSalesWeight) { - - if (postClothingSalesWeight.isBoxCollect()) { - boxCollectRepository.findByUserIdAndClothingSalesCount(postClothingSalesWeight.userId(), postClothingSalesWeight.clothingSalesCount()) - .ifPresent(boxCollect -> { - boxCollect.updateWeight(postClothingSalesWeight.weight()); - boxCollectRepository.save(boxCollect); - }); - } - else { - bagInitRepository.findByUserIdAndClothingSalesCount(postClothingSalesWeight.userId(), postClothingSalesWeight.clothingSalesCount()) - .ifPresent(bagInit -> { - bagInit.updateWeight(postClothingSalesWeight.weight()); - bagInitRepository.save(bagInit); - }); - } - - return true; + @Transactional + public void updateClothingSalesWeight(PatchClothingSalesWeight patchClothingSalesWeight) { + ClothingSales clothingSales = clothingSalesRepository.findById(patchClothingSalesWeight.clothingSalesId()) + .orElseThrow(() -> new CustomException(INVALID_CLOTHING_SALES_ID)); + clothingSales.updateWeight(patchClothingSalesWeight.weight()); + clothingSalesRepository.save(clothingSales); } - public PageResponse> getClothingSalesProduct(Long userId, Integer clothingSalesCount, ProductStateType productStateType, PageCondition pageCondition) { + public PageResponse> getClothingSalesProduct(Long clothingSalesId, ProductStateType productStateType, PageCondition pageCondition) { Page pages; if (productStateType == ProductStateType.SELLING || productStateType == ProductStateType.SOLD_OUT) { - pages = productRepository.getClothingSalesPendingProduct(userId, clothingSalesCount, productStateType, pageCondition.toPageable()); + pages = productRepository.getClothingSalesPendingProduct(clothingSalesId, productStateType, pageCondition.toPageable()); } else { - pages = productRepository.getClothingSalesCancelledProduct(userId, clothingSalesCount, productStateType, pageCondition.toPageable()); + pages = productRepository.getClothingSalesCancelledProduct(clothingSalesId, productStateType, pageCondition.toPageable()); } return PageResponse.of(pages.getContent(), pages.getTotalPages(), pages.getTotalElements()); } - public GetClothingSalesUser getClothingSalesUser(Long userId, Integer clothingSalesCount){ - String code = userId + "-" + clothingSalesCount; - User user = userRepository.findById(userId).orElseThrow(() -> new CustomException(USER_NOT_FOUND)); + public GetClothingSalesUser getClothingSalesUser(Long clothingSalesId){ + ClothingSales clothingSales = clothingSalesRepository.findById(clothingSalesId) + .orElseThrow(() -> new CustomException(INVALID_CLOTHING_SALES_ID)); + User user = clothingSales.getUser(); + String code = user.getId() + "-" + clothingSales.getClothingSalesCount(); return GetClothingSalesUser.of(code, user); } diff --git a/src/main/java/com/example/repick/domain/clothingSales/validator/ClothingSalesValidator.java b/src/main/java/com/example/repick/domain/clothingSales/validator/ClothingSalesValidator.java index 1048d4fb..7987e0a6 100644 --- a/src/main/java/com/example/repick/domain/clothingSales/validator/ClothingSalesValidator.java +++ b/src/main/java/com/example/repick/domain/clothingSales/validator/ClothingSalesValidator.java @@ -1,8 +1,5 @@ package com.example.repick.domain.clothingSales.validator; -import com.example.repick.domain.clothingSales.entity.BagInit; -import com.example.repick.domain.clothingSales.entity.BoxCollect; -import com.example.repick.domain.clothingSales.repository.BagCollectRepository; import com.example.repick.domain.product.entity.Product; import com.example.repick.domain.product.entity.ProductState; import com.example.repick.domain.product.entity.ProductStateType; @@ -19,28 +16,8 @@ @Service @RequiredArgsConstructor public class ClothingSalesValidator { - - private final BagCollectRepository bagCollectRepository; private final ProductStateRepository productSellingStateRepository; - public void userBagInitMatches(Long userId, BagInit bagInit) { - if (!userId.equals(bagInit.getUser().getId())) { - throw new CustomException(BAG_INIT_NOT_MATCH_USER); - } - } - - public void userBoxCollectMatches(Long userId, BoxCollect boxCollect) { - if (!userId.equals(boxCollect.getUser().getId())) { - throw new CustomException(BOX_COLLECT_NOT_MATCH_USER); - } - } - - public void duplicateBagCollectExists(Long bagInitId) { - bagCollectRepository.findByBagInitId(bagInitId).ifPresent(bagCollect -> { - throw new CustomException(BAG_COLLECT_DUPLICANT); - }); - } - public void productUserMatches(Product product, User user) { if (!Objects.equals(product.getUser().getId(), user.getId())) { throw new CustomException(ACCESS_DENIED); diff --git a/src/main/java/com/example/repick/domain/product/dto/product/PostProduct.java b/src/main/java/com/example/repick/domain/product/dto/product/PostProduct.java index 0ca0824c..88d0d979 100644 --- a/src/main/java/com/example/repick/domain/product/dto/product/PostProduct.java +++ b/src/main/java/com/example/repick/domain/product/dto/product/PostProduct.java @@ -1,5 +1,6 @@ package com.example.repick.domain.product.dto.product; +import com.example.repick.domain.clothingSales.entity.ClothingSales; import com.example.repick.domain.product.entity.*; import com.example.repick.domain.user.entity.User; import io.swagger.v3.oas.annotations.media.Schema; @@ -26,18 +27,20 @@ public record PostProduct ( @Schema(description = "상품 소재 목록") List materials ) { - public Product toRejectedProduct(User user) { + public Product toRejectedProduct(User user, ClothingSales clothingSales) { return Product.builder() .user(user) + .clothingSales(clothingSales) .clothingSalesCount(this.clothingSalesCount()) .productCode(this.productCode()) .productState(ProductStateType.REJECTED) .build(); } - public Product toProduct(User user, String size) { + public Product toProduct(User user, ClothingSales clothingSales, String size) { return Product.builder() .user(user) + .clothingSales(clothingSales) .clothingSalesCount(this.clothingSalesCount()) .productCode(this.productCode()) .productName(this.productName()) diff --git a/src/main/java/com/example/repick/domain/product/entity/Product.java b/src/main/java/com/example/repick/domain/product/entity/Product.java index 8b6034d5..d4bb2b2c 100644 --- a/src/main/java/com/example/repick/domain/product/entity/Product.java +++ b/src/main/java/com/example/repick/domain/product/entity/Product.java @@ -1,5 +1,6 @@ package com.example.repick.domain.product.entity; +import com.example.repick.domain.clothingSales.entity.ClothingSales; import com.example.repick.domain.user.entity.User; import com.example.repick.global.entity.BaseEntity; import jakarta.persistence.*; @@ -13,11 +14,18 @@ @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter public class Product extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @ManyToOne @JoinColumn(name = "user_id") private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "clothing_sales_id") + private ClothingSales clothingSales; + private Integer clothingSalesCount; private String productCode; private String productName; @@ -55,6 +63,7 @@ public class Product extends BaseEntity { @Builder public Product( User user, + ClothingSales clothingSales, Integer clothingSalesCount, String productCode, String productName, @@ -73,6 +82,7 @@ public Product( Gender gender, ProductStateType productState) { this.user = user; + this.clothingSales = clothingSales; this.clothingSalesCount = clothingSalesCount; this.productCode = productCode; this.productName = productName; 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 bdb6334c..c3fbc9e7 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 @@ -7,7 +7,9 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import javax.swing.text.html.Option; import java.util.List; +import java.util.Optional; public interface ProductOrderRepository extends JpaRepository { List findByPayment(Payment payment); @@ -18,4 +20,6 @@ public interface ProductOrderRepository extends JpaRepository findByProductOrderStateIn(List productOrderStates, Pageable pageable); + Optional findFirstByProductIdOrderByCreatedDateDesc(Long productId); + } diff --git a/src/main/java/com/example/repick/domain/product/repository/ProductRepositoryCustom.java b/src/main/java/com/example/repick/domain/product/repository/ProductRepositoryCustom.java index 40770990..3b343fca 100644 --- a/src/main/java/com/example/repick/domain/product/repository/ProductRepositoryCustom.java +++ b/src/main/java/com/example/repick/domain/product/repository/ProductRepositoryCustom.java @@ -42,7 +42,7 @@ Page findHighestDiscountProducts( Page findCartedProducts(Long userId, Pageable pageable); - List findProductDtoByUserIdAndClothingSalesCount(Long userId, Integer clothingSalesCount); + List findProductDtoByClothingSalesId(long clothingSalesId); List findByProductSellingStateType(ProductStateType productStateType); @@ -52,7 +52,7 @@ Page findHighestDiscountProducts( Page getClothingSalesProductCount(Pageable pageable); - Page getClothingSalesPendingProduct(Long userId, Integer clothingSalesCount, ProductStateType productStateType, Pageable pageable); + Page getClothingSalesPendingProduct(Long clothingSalesId, ProductStateType productStateType, Pageable pageable); - Page getClothingSalesCancelledProduct(Long userId, Integer clothingSalesCount, ProductStateType productStateType, Pageable pageable); + Page getClothingSalesCancelledProduct(Long clothingSalesId, ProductStateType productStateType, Pageable pageable); } diff --git a/src/main/java/com/example/repick/domain/product/repository/ProductRepositoryImpl.java b/src/main/java/com/example/repick/domain/product/repository/ProductRepositoryImpl.java index 5bfe8cc4..27510c33 100644 --- a/src/main/java/com/example/repick/domain/product/repository/ProductRepositoryImpl.java +++ b/src/main/java/com/example/repick/domain/product/repository/ProductRepositoryImpl.java @@ -24,8 +24,7 @@ import java.util.List; import java.util.stream.Collectors; -import static com.example.repick.domain.clothingSales.entity.QBagInit.bagInit; -import static com.example.repick.domain.clothingSales.entity.QBoxCollect.boxCollect; +import static com.example.repick.domain.clothingSales.entity.QClothingSales.clothingSales; import static com.example.repick.domain.product.entity.QProduct.product; import static com.example.repick.domain.product.entity.QProductCart.productCart; import static com.example.repick.domain.product.entity.QProductCategory.productCategory; @@ -311,7 +310,7 @@ public Page findMainPageRecommendation(Pageable pageable, L } @Override - public List findProductDtoByUserIdAndClothingSalesCount(Long userId, Integer clothingSalesCount) { + public List findProductDtoByClothingSalesId(long clothingSalesId) { return jpaQueryFactory .select(Projections.constructor(GetProductByClothingSalesDto.class, product.id, @@ -325,7 +324,8 @@ public List findProductDtoByUserIdAndClothingSales product.discountRate, product.predictPriceDiscountRate)) .from(product) - .where(product.clothingSalesCount.eq(clothingSalesCount) + .leftJoin(productState).on(product.id.eq(productState.productId)) + .where(product.clothingSales.id.eq(clothingSalesId) .and(product.isDeleted.isFalse()) .and(product.productState.eq(ProductStateType.PREPARING).or(product.productState.eq(ProductStateType.REJECTED)))) .distinct() @@ -388,20 +388,19 @@ public Page getClothingSalesProductCount(Pageable product.user.id.stringValue().concat("-").concat(product.clothingSalesCount.stringValue()), product.user.nickname, product.user.id, - bagInit.clothingSalesCount.coalesce(boxCollect.clothingSalesCount), + clothingSales.clothingSalesCount, product.count().intValue(), product.productState.when(ProductStateType.SELLING).then(1).otherwise(0).sum(), product.productState.when(ProductStateType.SOLD_OUT).then(1).otherwise(0).sum(), product.productState.when(ProductStateType.REJECTED).then(1).otherwise(0).sum(), product.productState.when(ProductStateType.SELLING_END).then(1).otherwise(0).sum(), - bagInit.weight.coalesce(boxCollect.weight).max(), - bagInit.createdDate.coalesce(boxCollect.createdDate).max() + clothingSales.weight, + clothingSales.createdDate )) .from(product) - .leftJoin(bagInit).on(product.user.id.eq(bagInit.user.id).and(product.clothingSalesCount.eq(bagInit.clothingSalesCount))) - .leftJoin(boxCollect).on(product.user.id.eq(boxCollect.user.id).and(product.clothingSalesCount.eq(boxCollect.clothingSalesCount))) + .leftJoin(clothingSales).on(product.clothingSales.id.eq(clothingSales.id)) .groupBy(product.user.id, product.clothingSalesCount) - .orderBy(bagInit.createdDate.coalesce(boxCollect.createdDate).max().desc()); + .orderBy(clothingSales.createdDate.max().desc()); long total = query.stream().count(); List content = query @@ -413,12 +412,11 @@ public Page getClothingSalesProductCount(Pageable } @Override - public Page getClothingSalesPendingProduct(Long userId, Integer clothingSalesCount, ProductStateType productStateType, Pageable pageable) { + public Page getClothingSalesPendingProduct(Long clothingSalesId, ProductStateType productStateType, Pageable pageable) { JPAQuery products = jpaQueryFactory .selectFrom(product) - .where(product.user.id.eq(userId) - .and(product.clothingSalesCount.eq(clothingSalesCount) - .and(product.productState.eq(productStateType)))); + .where(product.clothingSales.id.eq(clothingSalesId) + .and(product.productState.eq(productStateType))); long total = products.stream().count(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yy"); List contents = products @@ -448,12 +446,11 @@ public Page getClothingSalesPendingProduct(Long userId, } @Override - public Page getClothingSalesCancelledProduct(Long userId, Integer clothingSalesCount, ProductStateType productStateType, Pageable pageable) { + public Page getClothingSalesCancelledProduct(Long clothingSalesId, ProductStateType productStateType, Pageable pageable) { JPAQuery products = jpaQueryFactory .selectFrom(product) - .where(product.user.id.eq(userId) - .and(product.clothingSalesCount.eq(clothingSalesCount) - .and(product.productState.eq(productStateType)))); + .where(product.clothingSales.id.eq(clothingSalesId) + .and(product.productState.eq(productStateType))); long total = products.stream().count(); // TODO: Mock data 제거 및 반송 기능 구현 List contents = products @@ -476,7 +473,6 @@ public Page getClothingSalesCancelledProduct(Long userI return new PageImpl<>(contents, pageable, total); } - private BooleanExpression notExistsUserPreferenceProduct(Long userId) { return JPAExpressions diff --git a/src/main/java/com/example/repick/domain/product/service/ProductService.java b/src/main/java/com/example/repick/domain/product/service/ProductService.java index 54a6e0a0..7fe5fe6e 100644 --- a/src/main/java/com/example/repick/domain/product/service/ProductService.java +++ b/src/main/java/com/example/repick/domain/product/service/ProductService.java @@ -1,5 +1,7 @@ package com.example.repick.domain.product.service; +import com.example.repick.domain.clothingSales.entity.ClothingSales; +import com.example.repick.domain.clothingSales.repository.ClothingSalesRepository; import com.example.repick.domain.product.dto.product.*; import com.example.repick.domain.product.dto.productOrder.GetProductCart; import com.example.repick.domain.product.entity.*; @@ -41,6 +43,7 @@ public class ProductService { private final ProductMaterialRepository productMaterialRepository; private final ProductValidator productValidator; private final RecommendationService recommendationService; + private final ClothingSalesRepository clothingSalesRepository; private String uploadImage(List images, Product product) { String thumbnailGeneratedUrl = null; @@ -91,15 +94,16 @@ public ProductResponse registerProduct(List images, PostProduct p User user = userRepository.findById(postProduct.userId()) .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); - // validate clothing sales info - productValidator.validateClothingSales(postProduct.clothingSalesCount(), user.getId()); + // get clothingSales + ClothingSales clothingSales = clothingSalesRepository.findByUserAndClothingSalesCount(user, postProduct.clothingSalesCount()) + .orElseThrow(() -> new CustomException(CLOTHING_SALES_NOT_FOUND)); // handle rejected product if (postProduct.isRejected()) return ProductResponse.fromRejectedProduct(handleRejectedProduct(postProduct, user, images)); // product String size = convertSizeInfo(Category.fromName(postProduct.categories().get(0)), postProduct.sizeInfo()); - Product product = productRepository.save(postProduct.toProduct(user, size)); + Product product = productRepository.save(postProduct.toProduct(user, clothingSales, size)); // productImage String thumbnailGeneratedUrl = uploadImage(images, product); @@ -123,8 +127,10 @@ public ProductResponse registerProduct(List images, PostProduct p private Product handleRejectedProduct(PostProduct postProduct, User user, List images) { System.out.println("ProductService.handleRejectedProduct"); + ClothingSales clothingSales = clothingSalesRepository.findByUserAndClothingSalesCount(user, postProduct.clothingSalesCount()) + .orElseThrow(() -> new CustomException(CLOTHING_SALES_NOT_FOUND)); // product - Product product = productRepository.save(postProduct.toRejectedProduct(user)); + Product product = productRepository.save(postProduct.toRejectedProduct(user, clothingSales)); System.out.println("ProductService.handleRejectedProduct2"); // productImage diff --git a/src/main/java/com/example/repick/domain/product/validator/ProductValidator.java b/src/main/java/com/example/repick/domain/product/validator/ProductValidator.java index 26384b84..c1244fc1 100644 --- a/src/main/java/com/example/repick/domain/product/validator/ProductValidator.java +++ b/src/main/java/com/example/repick/domain/product/validator/ProductValidator.java @@ -1,9 +1,5 @@ package com.example.repick.domain.product.validator; -import com.example.repick.domain.clothingSales.entity.BagInit; -import com.example.repick.domain.clothingSales.entity.BoxCollect; -import com.example.repick.domain.clothingSales.repository.BagInitRepository; -import com.example.repick.domain.clothingSales.repository.BoxCollectRepository; import com.example.repick.domain.product.entity.ProductState; import com.example.repick.domain.product.entity.ProductStateType; import com.example.repick.domain.product.repository.ProductStateRepository; @@ -11,17 +7,12 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.util.Objects; -import java.util.Optional; - import static com.example.repick.global.error.exception.ErrorCode.*; @Service @RequiredArgsConstructor public class ProductValidator { private final ProductStateRepository productStateRepository; - private final BagInitRepository bagInitRepository; - private final BoxCollectRepository boxCollectRepository; public void validateProductState(Long productId, ProductStateType productStateType) { ProductState productState = productStateRepository.findFirstByProductIdOrderByCreatedDateDesc(productId) @@ -31,28 +22,4 @@ public void validateProductState(Long productId, ProductStateType productStateTy } } - public void validateClothingSales(Integer clothingSalesCount, Long userId) { - Optional bagInitOptional = bagInitRepository.findByUserIdAndClothingSalesCount(userId, clothingSalesCount); - - bagInitOptional.ifPresentOrElse(bagInit -> validateBagInit(bagInit, userId), () -> { - Optional boxCollectOptional = boxCollectRepository.findByUserIdAndClothingSalesCount(userId, clothingSalesCount); - - boxCollectOptional.ifPresentOrElse(boxCollect -> validateBoxCollect(boxCollect, userId), () -> { - throw new CustomException(INVALID_CLOTHING_SALES); - }); - }); - } - - private void validateBagInit(BagInit bagInit, Long userId) { - if (!Objects.equals(bagInit.getUser().getId(), userId)) { - throw new CustomException(BAG_INIT_NOT_MATCH_USER); - } - } - - private void validateBoxCollect(BoxCollect boxCollect, Long userId) { - if (!Objects.equals(boxCollect.getUser().getId(), userId)) { - throw new CustomException(BOX_COLLECT_NOT_MATCH_USER); - } - } - } diff --git a/src/main/java/com/example/repick/global/error/exception/ErrorCode.java b/src/main/java/com/example/repick/global/error/exception/ErrorCode.java index c63b279c..e6363308 100644 --- a/src/main/java/com/example/repick/global/error/exception/ErrorCode.java +++ b/src/main/java/com/example/repick/global/error/exception/ErrorCode.java @@ -40,16 +40,16 @@ public enum ErrorCode { PRODUCT_STATE_NOT_FOUND(400, "P030", "상품 상태가 존재하지 않습니다."), DUPLICATE_PRODUCT_CART(400, "P031", "이미 장바구니에 담긴 상품입니다."), // ClothingSales - INVALID_CLOTHING_SALES_STATE_NAME(400, "C001", "존재하지 않는 옷장 정리 상태 이름입니다."), + INVALID_CLOTHING_SALES_STATE_NAME(400, "C101", "존재하지 않는 옷장 정리 상태 이름입니다."), + INVALID_CLOTHING_SALES_ID(404, "C102", "존재하지 않거나 권한이 없는 옷장 정리 ID입니다."), + CLOTHING_SALES_NOT_FOUND(404, "C103", "존재하지 않는 옷장 정리입니다."), + CLOTHING_SALES_NOT_MATCH_USER(400, "C104", "옷장 정리와 사용자가 일치하지 않습니다."), // BagInit INVALID_BAG_INIT_ID(400, "B001", "존재하지 않는 백 요청 ID입니다."), // BagCollect INVALID_BAG_COLLECT_ID(400, "B101", "존재하지 않는 백 수거 ID입니다."), - BAG_INIT_NOT_MATCH_USER(400, "B102", "백 요청 ID와 사용자 ID가 일치하지 않습니다."), - BAG_COLLECT_DUPLICANT(400, "B103", "이미 수거된 백입니다."), // BoxCollect INVALID_BOX_COLLECT_ID(400, "B201", "존재하지 않는 박스 수거 ID입니다."), - BOX_COLLECT_NOT_MATCH_USER(400, "B202", "박스 수거 ID와 사용자 ID가 일치하지 않습니다."), // BagInitStateType INVALID_BAG_INIT_STATUS_ID(400, "B301", "존재하지 않는 백 요청 상태 ID입니다."), INVALID_BAG_INIT_STATUS_NAME(400, "B302", "존재하지 않는 백 요청 상태 이름입니다."), @@ -59,8 +59,6 @@ public enum ErrorCode { // BoxCollectStateType INVALID_BOX_COLLECT_STATUS_ID(400, "B501", "존재하지 않는 박스 수거 상태 ID입니다."), INVALID_BOX_COLLECT_STATUS_NAME(400, "B502", "존재하지 않는 박스 수거 상태 이름입니다."), - // ClothingSales - INVALID_CLOTHING_SALES(400, "B601", "존재하지 않는 수거 요청입니다."), // ProductSellingState INVALID_SELLING_STATE_ID(400, "P031", "존재하지 않는 판매 상태 ID입니다."), INVALID_SELLING_STATE_NAME(400, "P042", "존재하지 않는 판매 상태 이름입니다."),