Skip to content

Commit

Permalink
hotfix: change QualityRate enum
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunihs committed Aug 22, 2024
1 parent d60aec5 commit bba1831
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record GetProductDetail(
@Schema(description = "μƒν’ˆ μΉ΄ν…Œκ³ λ¦¬ 리슀트") List<String> 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,
Expand All @@ -32,7 +32,7 @@ public static GetProductDetail of(Product product, List<ProductImage> 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -25,7 +25,7 @@ public static GetProductThumbnail fromProduct(Product product) {
product.getDiscountRate(),
product.getPredictPriceDiscountRate(),
product.getBrandName(),
product.getQualityRate().name(),
product.getQualityRate().getValue(),
false
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> materials
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> materials
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +56,7 @@ private Page<GetProductThumbnail> findProducts(
product.discountRate,
product.predictPriceDiscountRate,
product.brandName,
product.qualityRate.stringValue(),
getQualityRateValue(),
productLike.id.isNotNull()))
.from(product)
.leftJoin(productLike)
Expand Down Expand Up @@ -124,7 +126,7 @@ public Page<GetProductThumbnail> findLikedProducts(String category, Long userId,
product.discountRate,
product.predictPriceDiscountRate,
product.brandName,
product.qualityRate.stringValue(),
getQualityRateValue(),
productLike.id.isNotNull()))
.from(product)
.leftJoin(productLike)
Expand Down Expand Up @@ -178,6 +180,15 @@ public Page<GetProductCart> 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);
}
Expand Down Expand Up @@ -222,7 +233,13 @@ private BooleanExpression brandFilter(String brandName) {
}

private BooleanExpression qualityFilter(List<String> qualityRates) {
return qualityRates != null ? product.qualityRate.stringValue().in(qualityRates) : null;
if (qualityRates == null || qualityRates.isEmpty()) {
return null;
}
List<QualityRate> qualityRateList = qualityRates.stream()
.map(QualityRate::fromValue)
.collect(Collectors.toList());
return product.qualityRate.in(qualityRateList);
}

private BooleanExpression sizesFilter(List<String> sizes) {
Expand Down Expand Up @@ -271,7 +288,7 @@ private BooleanExpression stylesFilter(List<String> styles) {

@Override
public Page<GetProductThumbnail> findMainPageRecommendation(Pageable pageable, Long userId, String gender, List<String> subCategories) {
JPAQuery<GetProductThumbnail> query = jpaQueryFactory
JPAQuery<GetProductThumbnail> query = jpaQueryFactory
.select(Projections.constructor(GetProductThumbnail.class,
product.id,
product.thumbnailImageUrl,
Expand All @@ -281,7 +298,7 @@ public Page<GetProductThumbnail> findMainPageRecommendation(Pageable pageable, L
product.discountRate,
product.predictPriceDiscountRate,
product.brandName,
product.qualityRate.stringValue(),
getQualityRateValue(),
productLike.id.isNotNull()))
.from(product)
.leftJoin(productLike)
Expand Down Expand Up @@ -445,7 +462,7 @@ public Page<GetProductsClothingSales> getClothingSalesProduct(Long clothingSales
p.getProductCode(),
p.getThumbnailImageUrl(),
p.getProductName(),
p.getQualityRate().toString(),
p.getQualityRate().getValue(),
dateRange,
p.getDiscountPrice(),
p.getSettlement(),
Expand Down Expand Up @@ -499,7 +516,7 @@ public Page<GetKgSellProductClothingSales> 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 λ§€μž… μ •μ‚° ν”Œλ‘œμš°
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit bba1831

Please sign in to comment.