From bba183116bc6e62c0ff4ec07a2feda9ecbedd7bf Mon Sep 17 00:00:00 2001 From: Jeonghyun Lee Date: Thu, 22 Aug 2024 22:29:44 +0900 Subject: [PATCH] hotfix: change QualityRate enum --- .../product/dto/product/GetProductDetail.java | 4 +-- .../dto/product/GetProductThumbnail.java | 4 +-- .../product/dto/product/PatchProduct.java | 2 +- .../product/dto/product/PostProduct.java | 2 +- .../product/dto/product/ProductResponse.java | 4 +-- .../domain/product/entity/QualityRate.java | 4 +-- .../repository/ProductRepositoryImpl.java | 31 ++++++++++++++----- .../recommendation/dto/GetRecommendation.java | 4 +-- 8 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/example/repick/domain/product/dto/product/GetProductDetail.java b/src/main/java/com/example/repick/domain/product/dto/product/GetProductDetail.java index aff604db..efa3f19c 100644 --- a/src/main/java/com/example/repick/domain/product/dto/product/GetProductDetail.java +++ b/src/main/java/com/example/repick/domain/product/dto/product/GetProductDetail.java @@ -12,7 +12,7 @@ public record GetProductDetail( @Schema(description = "상품 카테고리 리스트") List categoryList, @Schema(description = "브랜드 이름", example = "무인양품") String brandName, @Schema(description = "상품명", example = "블랙 카라 오버핏 셔츠") String productName, - @Schema(description = "상품 품질 등급 (S, A, B)", example = "S") String qualityRate, + @Schema(description = "상품 품질 등급 (A+, A, A-)", example = "A") String qualityRate, @Schema(description = "상품 가격(할인 전)", example = "40000") Long price, @Schema(description = "할인 가격", example = "15000") Long discountPrice, @Schema(description = "할인율",example = "30") Long discountRate, @@ -32,7 +32,7 @@ public static GetProductDetail of(Product product, List productIma productCategoryList.stream().map(productCategory -> productCategory.getCategory().getValue()).toList(), product.getBrandName(), product.getProductName(), - product.getQualityRate().name(), + product.getQualityRate().getValue(), product.getPrice(), product.getDiscountPrice(), product.getDiscountRate(), diff --git a/src/main/java/com/example/repick/domain/product/dto/product/GetProductThumbnail.java b/src/main/java/com/example/repick/domain/product/dto/product/GetProductThumbnail.java index 5e4ab032..631dc5ed 100644 --- a/src/main/java/com/example/repick/domain/product/dto/product/GetProductThumbnail.java +++ b/src/main/java/com/example/repick/domain/product/dto/product/GetProductThumbnail.java @@ -12,7 +12,7 @@ public record GetProductThumbnail( @Schema(description = "할인율",example = "30") Long discountRate, @Schema(description = "예측 정가 대비 할인율",example = "30") Long predictDiscountRate, @Schema(description = "브랜드 이름", example = "무인양품") String brandName, - @Schema(description = "상품 품질 등급 (S, A, B)", example = "S") String qualityRate, + @Schema(description = "상품 품질 등급 (A+, A, A-)", example = "A") String qualityRate, @Schema(description = "좋아요 여부", example = "False") Boolean isLiked ) { public static GetProductThumbnail fromProduct(Product product) { @@ -25,7 +25,7 @@ public static GetProductThumbnail fromProduct(Product product) { product.getDiscountRate(), product.getPredictPriceDiscountRate(), product.getBrandName(), - product.getQualityRate().name(), + product.getQualityRate().getValue(), false ); } diff --git a/src/main/java/com/example/repick/domain/product/dto/product/PatchProduct.java b/src/main/java/com/example/repick/domain/product/dto/product/PatchProduct.java index 3a5ee594..796a1f12 100644 --- a/src/main/java/com/example/repick/domain/product/dto/product/PatchProduct.java +++ b/src/main/java/com/example/repick/domain/product/dto/product/PatchProduct.java @@ -17,7 +17,7 @@ public record PatchProduct ( @Schema(description = "브랜드 이름", example = "무인양품") String brandName, @Schema(description = "상품 설명", example = "바람이 잘 통하는 시원한 오버핏 셔츠입니다.") String description, @Schema(description = "치수 정보") Size sizeInfo, - @Schema(description = "상품 품질 등급 (S, A, B)", example = "S") String qualityRate, + @Schema(description = "상품 품질 등급 (A+, A, A-)", example = "A") String qualityRate, @Schema(description = "상품 성별 (남성, 여성, 공용)", example = "남성") String gender, @Schema(description = "상품 소재 목록", example = "면, 나일론") List materials ) { 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 e46868d3..71eb6a44 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 @@ -22,7 +22,7 @@ public record PostProduct ( @Schema(description = "상품 설명", example = "바람이 잘 통하는 시원한 오버핏 셔츠입니다.") String description, @Schema(description = "치수 정보") Size sizeInfo, - @Schema(description = "상품 품질 등급 (S, A, B)", example = "S") String qualityRate, + @Schema(description = "상품 품질 등급 (A+, A, A-)", example = "A") String qualityRate, @Schema(description = "상품 성별 (남성, 여성, 공용)", example = "남성") String gender, @Schema(description = "상품 소재 목록") List materials ) { diff --git a/src/main/java/com/example/repick/domain/product/dto/product/ProductResponse.java b/src/main/java/com/example/repick/domain/product/dto/product/ProductResponse.java index ac11b75d..3b74b91d 100644 --- a/src/main/java/com/example/repick/domain/product/dto/product/ProductResponse.java +++ b/src/main/java/com/example/repick/domain/product/dto/product/ProductResponse.java @@ -15,7 +15,7 @@ public record ProductResponse( @Schema(description = "브랜드 이름", example = "무인양품") String brandName, @Schema(description = "상품 설명", example = "바람이 잘 통하는 시원한 오버핏 셔츠입니다.") String description, @Schema(description = "사이즈 (XXS, XS, S, M, L, XL, XXL)", example = "XXS") String size, - @Schema(description = "상품 품질 등급 (S, A, B)", example = "S") String qualityRate, + @Schema(description = "상품 품질 등급 (A+, A, A-)", example = "A") String qualityRate, @Schema(description = "상품 성별 (남성, 여성, 공용)", example = "남성") String gender ) { public ProductResponse(Long id, Long userId, Integer clothingSalesCount) { @@ -35,7 +35,7 @@ public static ProductResponse fromProduct(Product product) { product.getBrandName(), product.getDescription(), product.getSize(), - product.getQualityRate().name(), + product.getQualityRate().getValue(), product.getGender().name() ); } diff --git a/src/main/java/com/example/repick/domain/product/entity/QualityRate.java b/src/main/java/com/example/repick/domain/product/entity/QualityRate.java index 5374e71b..f5e5582f 100644 --- a/src/main/java/com/example/repick/domain/product/entity/QualityRate.java +++ b/src/main/java/com/example/repick/domain/product/entity/QualityRate.java @@ -6,9 +6,9 @@ @Getter public enum QualityRate { - S(1, "S"), + A_PLUS(1, "A+"), A(2, "A"), - B(3, "B"); + A_MINUS(3, "A-"); private final int id; private final String value; 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 783adf85..25d7cb26 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 @@ -11,6 +11,8 @@ import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.core.types.dsl.CaseBuilder; +import com.querydsl.core.types.dsl.StringExpression; import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -54,7 +56,7 @@ private Page findProducts( product.discountRate, product.predictPriceDiscountRate, product.brandName, - product.qualityRate.stringValue(), + getQualityRateValue(), productLike.id.isNotNull())) .from(product) .leftJoin(productLike) @@ -124,7 +126,7 @@ public Page findLikedProducts(String category, Long userId, product.discountRate, product.predictPriceDiscountRate, product.brandName, - product.qualityRate.stringValue(), + getQualityRateValue(), productLike.id.isNotNull())) .from(product) .leftJoin(productLike) @@ -178,6 +180,15 @@ public Page findCartedProducts(Long userId, Pageable pageable) { return new PageImpl<>(content, pageable, total); } + private StringExpression getQualityRateValue() { + return new CaseBuilder() + .when(product.qualityRate.eq(QualityRate.A_PLUS)).then("A+") + .when(product.qualityRate.eq(QualityRate.A)).then("A") + .when(product.qualityRate.eq(QualityRate.A_MINUS)).then("A-") + .otherwise("Unknown"); + } + + private BooleanExpression cartFilter(Long userId) { return productCart.userId.eq(userId); } @@ -222,7 +233,13 @@ private BooleanExpression brandFilter(String brandName) { } private BooleanExpression qualityFilter(List qualityRates) { - return qualityRates != null ? product.qualityRate.stringValue().in(qualityRates) : null; + if (qualityRates == null || qualityRates.isEmpty()) { + return null; + } + List qualityRateList = qualityRates.stream() + .map(QualityRate::fromValue) + .collect(Collectors.toList()); + return product.qualityRate.in(qualityRateList); } private BooleanExpression sizesFilter(List sizes) { @@ -271,7 +288,7 @@ private BooleanExpression stylesFilter(List styles) { @Override public Page findMainPageRecommendation(Pageable pageable, Long userId, String gender, List subCategories) { - JPAQuery query = jpaQueryFactory + JPAQuery query = jpaQueryFactory .select(Projections.constructor(GetProductThumbnail.class, product.id, product.thumbnailImageUrl, @@ -281,7 +298,7 @@ public Page findMainPageRecommendation(Pageable pageable, L product.discountRate, product.predictPriceDiscountRate, product.brandName, - product.qualityRate.stringValue(), + getQualityRateValue(), productLike.id.isNotNull())) .from(product) .leftJoin(productLike) @@ -445,7 +462,7 @@ public Page getClothingSalesProduct(Long clothingSales p.getProductCode(), p.getThumbnailImageUrl(), p.getProductName(), - p.getQualityRate().toString(), + p.getQualityRate().getValue(), dateRange, p.getDiscountPrice(), p.getSettlement(), @@ -499,7 +516,7 @@ public Page getClothingSalesKgSellProduct(Long cl p.getProductCode(), p.getThumbnailImageUrl(), p.getProductName(), - p.getQualityRate().toString(), + p.getQualityRate().getValue(), p.getClothingSales().getReturnRequestDate().format(DateTimeFormatter.ofPattern("MM/dd/yy")), isExpired != null ? isExpired : p.getProductState().equals(ProductStateType.SELLING_END), null // TODO: kg 매입 정산 플로우 diff --git a/src/main/java/com/example/repick/domain/recommendation/dto/GetRecommendation.java b/src/main/java/com/example/repick/domain/recommendation/dto/GetRecommendation.java index 870ae0fe..dc101938 100644 --- a/src/main/java/com/example/repick/domain/recommendation/dto/GetRecommendation.java +++ b/src/main/java/com/example/repick/domain/recommendation/dto/GetRecommendation.java @@ -11,10 +11,10 @@ public record GetRecommendation ( @Schema(description = "할인 가격", example = "15000") Long discountPrice, @Schema(description = "할인율",example = "30") Long discountRate, @Schema(description = "브랜드 이름", example = "무인양품") String brandName, - @Schema(description = "상품 품질 등급 (S, A, B)", example = "S") String qualityRate + @Schema(description = "상품 품질 등급 (A+, A, A-)", example = "A") String qualityRate ) { public GetRecommendation(Product product) { - this(product.getId(), product.getThumbnailImageUrl(), product.getProductName(), product.getPrice(), product.getDiscountPrice(), product.getDiscountRate(), product.getBrandName(), product.getQualityRate().name()); + this(product.getId(), product.getThumbnailImageUrl(), product.getProductName(), product.getPrice(), product.getDiscountPrice(), product.getDiscountRate(), product.getBrandName(), product.getQualityRate().getValue()); } }