Skip to content

Commit

Permalink
Refactor/product (#41)
Browse files Browse the repository at this point in the history
* refactor: delete unused field in dto

* refactor: get products

* refactor: productRepository findProducts

* refactor: productSellingStateType parameter
  • Loading branch information
hyunihs authored Apr 26, 2024
1 parent b1c9711 commit 1316e36
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ public SuccessResponse<List<GetProductThumbnail>> getMainPageRecommendation(
return SuccessResponse.success(productService.getMainPageRecommendation(gender, cursorId, pageSize));
}

@Operation(summary = "์ตœ์‹ ์ˆœ ์กฐํšŒ",
description = """
์ตœ์‹ ์ˆœ์œผ๋กœ ์ƒํ’ˆ ๋ฆฌ์ŠคํŠธ ํŽ˜์ด์ง€๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค. ๋ฌดํ•œ์Šคํฌ๋กค ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
@Operation(summary = "์ƒํ’ˆ ์กฐํšŒ",
description = """
์ตœ์‹ ์ˆœ, ๊ฐ€๊ฒฉ ๋‚ฎ์€์ˆœ, ๊ฐ€๊ฒฉ ๋†’์€์ˆœ, ํ• ์ธ์œจ ๋†’์€์ˆœ์œผ๋กœ ์ƒํ’ˆ ๋ฆฌ์ŠคํŠธ ํŽ˜์ด์ง€๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.
๋ฌดํ•œ์Šคํฌ๋กค ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
๊ฐ๊ฐ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” ์˜ต์…”๋„์ž…๋‹ˆ๋‹ค.
""")
@GetMapping("/latest")
public SuccessResponse<List<GetProductThumbnail>> getLatestProduct(
@GetMapping("/{type}")
public SuccessResponse<List<GetProductThumbnail>> getProducts(
@Parameter(description = "์กฐํšŒ ํƒ€์ž… (latest, lowest-price, highest-price, highest-discount)") @PathVariable String type,
@Parameter(description = "์กฐํšŒ ์˜๋ฅ˜ ์„ฑ๋ณ„") @RequestParam(required = false) String gender,
@Parameter(description = "์นดํ…Œ๊ณ ๋ฆฌ") @RequestParam(required = false) String category,
@Parameter(description = "์Šคํƒ€์ผ") @RequestParam(required = false) List<String> styles,
Expand All @@ -88,74 +90,8 @@ public SuccessResponse<List<GetProductThumbnail>> getLatestProduct(
@Parameter(description = "์‚ฌ์ด์ฆˆ") @RequestParam(required = false) List<String> sizes,
@Parameter(description = "1๋ฒˆ์งธ ํŽ˜์ด์ง€ ์กฐํšŒ์‹œ null, " +
"2๋ฒˆ์งธ ์ด์ƒ ํŽ˜์ด์ง€ ์กฐํšŒ์‹œ ์ง์ „ ํŽ˜์ด์ง€์˜ ๋งˆ์ง€๋ง‰ episode id") @RequestParam(required = false) Long cursorId,
@Parameter(description = "ํ•œ ํŽ˜์ด์ง€์— ๊ฐ€์ ธ์˜ฌ ์—ํ”ผ์†Œ๋“œ ๊ฐœ์ˆ˜, ๊ธฐ๋ณธ๊ฐ’ 4") @RequestParam(required = false) Integer pageSize) {
return SuccessResponse.success(productService.getLatest(gender, category, styles, minPrice, maxPrice, brandNames, qualityRates, sizes, cursorId, pageSize));
}

@Operation(summary = "๊ฐ€๊ฒฉ ๋‚ฎ์€์ˆœ ์กฐํšŒ",
description = """
๊ฐ€๊ฒฉ ๋‚ฎ์€์ˆœ์œผ๋กœ ์ƒํ’ˆ ๋ฆฌ์ŠคํŠธ ํŽ˜์ด์ง€๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค. ๋ฌดํ•œ์Šคํฌ๋กค ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
๊ฐ๊ฐ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” ์˜ต์…”๋„์ž…๋‹ˆ๋‹ค.
""")
@GetMapping("/lowest-price")
public SuccessResponse<List<GetProductThumbnail>> getLowestProduct(
@Parameter(description = "์กฐํšŒ ์˜๋ฅ˜ ์„ฑ๋ณ„") @RequestParam(required = false) String gender,
@Parameter(description = "์นดํ…Œ๊ณ ๋ฆฌ") @RequestParam(required = false) String category,
@Parameter(description = "์Šคํƒ€์ผ") @RequestParam(required = false) List<String> styles,
@Parameter(description = "์ตœ์†Œ ๊ฐ€๊ฒฉ") @RequestParam(required = false) Long minPrice,
@Parameter(description = "์ตœ๋Œ€ ๊ฐ€๊ฒฉ") @RequestParam(required = false) Long maxPrice,
@Parameter(description = "๋ธŒ๋žœ๋“œ") @RequestParam(required = false) List<String> brandNames,
@Parameter(description = "์ƒํ’ˆ๋“ฑ๊ธ‰") @RequestParam(required = false) List<String> qualityRates,
@Parameter(description = "์‚ฌ์ด์ฆˆ") @RequestParam(required = false) List<String> sizes,
@Parameter(description = "1๋ฒˆ์งธ ํŽ˜์ด์ง€ ์กฐํšŒ์‹œ null, " +
"2๋ฒˆ์งธ ์ด์ƒ ํŽ˜์ด์ง€ ์กฐํšŒ์‹œ ์ง์ „ ํŽ˜์ด์ง€์˜ ๋งˆ์ง€๋ง‰ episode id") @RequestParam(required = false) Long cursorId,
@Parameter(description = "ํ•œ ํŽ˜์ด์ง€์— ๊ฐ€์ ธ์˜ฌ ์—ํ”ผ์†Œ๋“œ ๊ฐœ์ˆ˜, ๊ธฐ๋ณธ๊ฐ’ 4") @RequestParam(required = false) Integer pageSize) {
return SuccessResponse.success(productService.getLowest(gender, category, styles, minPrice, maxPrice, brandNames, qualityRates, sizes, cursorId, pageSize));
}

@Operation(summary = "๊ฐ€๊ฒฉ ๋†’์€์ˆœ ์กฐํšŒ",
description = """
๊ฐ€๊ฒฉ ๋†’์€์ˆœ์œผ๋กœ ์ƒํ’ˆ ๋ฆฌ์ŠคํŠธ ํŽ˜์ด์ง€๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค. ๋ฌดํ•œ์Šคํฌ๋กค ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
๊ฐ๊ฐ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” ์˜ต์…”๋„์ž…๋‹ˆ๋‹ค.
""")
@GetMapping("/highest-price")
public SuccessResponse<List<GetProductThumbnail>> getHighestProduct(
@Parameter(description = "์กฐํšŒ ์˜๋ฅ˜ ์„ฑ๋ณ„") @RequestParam(required = false) String gender,
@Parameter(description = "์นดํ…Œ๊ณ ๋ฆฌ") @RequestParam(required = false) String category,
@Parameter(description = "์Šคํƒ€์ผ") @RequestParam(required = false) List<String> styles,
@Parameter(description = "์ตœ์†Œ ๊ฐ€๊ฒฉ") @RequestParam(required = false) Long minPrice,
@Parameter(description = "์ตœ๋Œ€ ๊ฐ€๊ฒฉ") @RequestParam(required = false) Long maxPrice,
@Parameter(description = "๋ธŒ๋žœ๋“œ") @RequestParam(required = false) List<String> brandNames,
@Parameter(description = "์ƒํ’ˆ๋“ฑ๊ธ‰") @RequestParam(required = false) List<String> qualityRates,
@Parameter(description = "์‚ฌ์ด์ฆˆ") @RequestParam(required = false) List<String> sizes,
@Parameter(description = "1๋ฒˆ์งธ ํŽ˜์ด์ง€ ์กฐํšŒ์‹œ null, " +
"2๋ฒˆ์งธ ์ด์ƒ ํŽ˜์ด์ง€ ์กฐํšŒ์‹œ ์ง์ „ ํŽ˜์ด์ง€์˜ ๋งˆ์ง€๋ง‰ episode id") @RequestParam(required = false) Long cursorId,
@Parameter(description = "ํ•œ ํŽ˜์ด์ง€์— ๊ฐ€์ ธ์˜ฌ ์—ํ”ผ์†Œ๋“œ ๊ฐœ์ˆ˜, ๊ธฐ๋ณธ๊ฐ’ 4") @RequestParam(required = false) Integer pageSize) {
return SuccessResponse.success(productService.getHighest(gender, category, styles, minPrice, maxPrice, brandNames, qualityRates, sizes, cursorId, pageSize));
}

@Operation(summary = "ํ• ์ธ์œจ ๋†’์€์ˆœ ์กฐํšŒ",
description = """
ํ• ์ธ์œจ ๋†’์€์ˆœ์œผ๋กœ ์ƒํ’ˆ ๋ฆฌ์ŠคํŠธ ํŽ˜์ด์ง€๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค. ๋ฌดํ•œ์Šคํฌ๋กค ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
๊ฐ๊ฐ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋Š” ์˜ต์…”๋„์ž…๋‹ˆ๋‹ค.
""")
@GetMapping("/highest-discount")
public SuccessResponse<List<GetProductThumbnail>> getHighestDiscountProduct(
@Parameter(description = "์กฐํšŒ ์˜๋ฅ˜ ์„ฑ๋ณ„") @RequestParam(required = false) String gender,
@Parameter(description = "์นดํ…Œ๊ณ ๋ฆฌ") @RequestParam(required = false) String category,
@Parameter(description = "์Šคํƒ€์ผ") @RequestParam(required = false) List<String> styles,
@Parameter(description = "์ตœ์†Œ ๊ฐ€๊ฒฉ") @RequestParam(required = false) Long minPrice,
@Parameter(description = "์ตœ๋Œ€ ๊ฐ€๊ฒฉ") @RequestParam(required = false) Long maxPrice,
@Parameter(description = "๋ธŒ๋žœ๋“œ") @RequestParam(required = false) List<String> brandNames,
@Parameter(description = "์ƒํ’ˆ๋“ฑ๊ธ‰") @RequestParam(required = false) List<String> qualityRates,
@Parameter(description = "์‚ฌ์ด์ฆˆ") @RequestParam(required = false) List<String> sizes,
@Parameter(description = "1๋ฒˆ์งธ ํŽ˜์ด์ง€ ์กฐํšŒ์‹œ null, " +
"2๋ฒˆ์งธ ์ด์ƒ ํŽ˜์ด์ง€ ์กฐํšŒ์‹œ ์ง์ „ ํŽ˜์ด์ง€์˜ ๋งˆ์ง€๋ง‰ episode id") @RequestParam(required = false) Long cursorId,
@Parameter(description = "ํ•œ ํŽ˜์ด์ง€์— ๊ฐ€์ ธ์˜ฌ ์—ํ”ผ์†Œ๋“œ ๊ฐœ์ˆ˜, ๊ธฐ๋ณธ๊ฐ’ 4") @RequestParam(required = false) Integer pageSize) {
return SuccessResponse.success(productService.getHighestDiscount(gender, category, styles, minPrice, maxPrice, brandNames, qualityRates, sizes, cursorId, pageSize));
@Parameter(description = "ํ•œ ํŽ˜์ด์ง€์— ๊ฐ€์ ธ์˜ฌ ์—ํ”ผ์†Œ๋“œ ๊ฐœ์ˆ˜, ๊ธฐ๋ณธ๊ฐ’ 4") @RequestParam(required = false) Integer pageSize){
return SuccessResponse.success(productService.getProducts(type, gender, category, styles, minPrice, maxPrice, brandNames, qualityRates, sizes, cursorId, pageSize));
}

// TODO: !!ADMIN ACCESS REQUIRED!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
public record PostPayment(
@Schema(description = "๊ฒฐ์ œ ๊ณ ์œ ๋ฒˆํ˜ธ") String iamportUid,
@Schema(description = "์ฃผ๋ฌธ ์•„์ด๋””") String merchantUid,
@Schema(description = "๊ฒฐ์ œ ๊ธˆ์•ก") Long paymentAmount,
Address address) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ List<GetProductThumbnail> findLatestProducts(
List<String> sizes,
Long cursorId,
Integer pageSize,
Long userId,
ProductSellingStateType productSellingStateType);
Long userId);

List<GetProductThumbnail> findLowestProducts(
String gender,
Expand All @@ -34,8 +33,7 @@ List<GetProductThumbnail> findLowestProducts(
List<String> sizes,
Long cursorId,
Integer pageSize,
Long userId,
ProductSellingStateType productSellingStateType);
Long userId);

List<GetProductThumbnail> findHighestProducts(
String gender,
Expand All @@ -48,8 +46,7 @@ List<GetProductThumbnail> findHighestProducts(
List<String> sizes,
Long cursorId,
Integer pageSize,
Long userId,
ProductSellingStateType productSellingStateType);
Long userId);

List<GetProductThumbnail> findHighestDiscountProducts(
String gender,
Expand All @@ -62,8 +59,7 @@ List<GetProductThumbnail> findHighestDiscountProducts(
List<String> sizes,
Long cursorId,
Integer pageSize,
Long userId,
ProductSellingStateType productSellingStateType);
Long userId);

List<GetProductThumbnail> findMainPageRecommendation(Long cursorId, Integer pageSize, Long userId, String gender, ProductSellingStateType productSellingStateType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.example.repick.domain.product.entity.Gender;
import com.example.repick.domain.product.entity.ProductSellingStateType;
import com.example.repick.domain.product.entity.Style;
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.Expressions;
Expand All @@ -29,8 +30,7 @@ public class ProductRepositoryImpl implements ProductRepositoryCustom {

private final JPAQueryFactory jpaQueryFactory;

@Override
public List<GetProductThumbnail> findLatestProducts(
private List<GetProductThumbnail> findProducts(
String gender,
String category,
List<String> styles,
Expand All @@ -42,7 +42,7 @@ public List<GetProductThumbnail> findLatestProducts(
Long cursorId,
Integer pageSize,
Long userId,
ProductSellingStateType productSellingStateType) {
OrderSpecifier<?> orderBy) {

return jpaQueryFactory
.select(Projections.constructor(GetProductThumbnail.class,
Expand Down Expand Up @@ -74,8 +74,8 @@ public List<GetProductThumbnail> findLatestProducts(
sizesFilter(sizes),
ltProductId(cursorId),
deletedFilter(),
sellingStateFilter(productSellingStateType))
.orderBy(product.id.desc())
sellingStateFilter(ProductSellingStateType.SELLING))
.orderBy(orderBy)
.limit(pageSize)
.fetch()
.stream()
Expand All @@ -84,165 +84,31 @@ public List<GetProductThumbnail> findLatestProducts(
}

@Override
public List<GetProductThumbnail> findLowestProducts(
String gender,
String category,
List<String> styles,
Long minPrice,
Long maxPrice,
List<String> brandNames,
List<String> qualityRates,
List<String> sizes,
Long cursorId,
Integer pageSize,
Long userId,
ProductSellingStateType productSellingStateType) {
public List<GetProductThumbnail> findLatestProducts(
String gender, String category, List<String> styles, Long minPrice, Long maxPrice, List<String> brandNames,
List<String> qualityRates, List<String> sizes, Long cursorId, Integer pageSize, Long userId) {
return findProducts(gender, category, styles, minPrice, maxPrice, brandNames, qualityRates, sizes, cursorId, pageSize, userId, product.id.desc());
}

return jpaQueryFactory
.select(Projections.constructor(GetProductThumbnail.class,
product.id,
product.thumbnailImageUrl,
product.productName,
product.price,
product.discountRate,
product.brandName,
product.qualityRate.stringValue(),
productLike.id.isNotNull()))
.from(product)
.leftJoin(productLike)
.on(product.id.eq(productLike.productId)
.and(productLike.userId.eq(userId)))
.leftJoin(productStyle)
.on(product.id.eq(productStyle.product.id))
.leftJoin(productCategory)
.on(product.id.eq(productCategory.product.id))
.leftJoin(productSellingState)
.on(product.id.eq(productSellingState.productId))
.where(
genderFilter(gender),
categoryFilter(category),
stylesFilter(styles),
priceFilter(minPrice, maxPrice),
brandFilter(brandNames),
qualityFilter(qualityRates),
sizesFilter(sizes),
ltProductId(cursorId),
deletedFilter(),
sellingStateFilter(productSellingStateType))
.orderBy(product.price.asc())
.limit(pageSize)
.fetch()
.stream()
.distinct()
.collect(Collectors.toList());
@Override
public List<GetProductThumbnail> findLowestProducts(
String gender, String category, List<String> styles, Long minPrice, Long maxPrice, List<String> brandNames,
List<String> qualityRates, List<String> sizes, Long cursorId, Integer pageSize, Long userId) {
return findProducts(gender, category, styles, minPrice, maxPrice, brandNames, qualityRates, sizes, cursorId, pageSize, userId, product.price.asc());
}

@Override
public List<GetProductThumbnail> findHighestProducts(
String gender,
String category,
List<String> styles,
Long minPrice,
Long maxPrice,
List<String> brandNames,
List<String> qualityRates,
List<String> sizes,
Long cursorId,
Integer pageSize,
Long userId,
ProductSellingStateType productSellingStateType) {

return jpaQueryFactory
.select(Projections.constructor(GetProductThumbnail.class,
product.id,
product.thumbnailImageUrl,
product.productName,
product.price,
product.discountRate,
product.brandName,
product.qualityRate.stringValue(),
productLike.id.isNotNull()))
.from(product)
.leftJoin(productLike)
.on(product.id.eq(productLike.productId)
.and(productLike.userId.eq(userId)))
.leftJoin(productStyle)
.on(product.id.eq(productStyle.product.id))
.leftJoin(productCategory)
.on(product.id.eq(productCategory.product.id))
.leftJoin(productSellingState)
.on(product.id.eq(productSellingState.productId))
.where(
genderFilter(gender),
categoryFilter(category),
stylesFilter(styles),
priceFilter(minPrice, maxPrice),
brandFilter(brandNames),
qualityFilter(qualityRates),
sizesFilter(sizes),
ltProductId(cursorId),
deletedFilter(),
sellingStateFilter(productSellingStateType))
.orderBy(product.price.desc())
.limit(pageSize)
.fetch()
.stream()
.distinct()
.collect(Collectors.toList());
String gender, String category, List<String> styles, Long minPrice, Long maxPrice, List<String> brandNames,
List<String> qualityRates, List<String> sizes, Long cursorId, Integer pageSize, Long userId) {
return findProducts(gender, category, styles, minPrice, maxPrice, brandNames, qualityRates, sizes, cursorId, pageSize, userId, product.price.desc());
}

@Override
public List<GetProductThumbnail> findHighestDiscountProducts(
String gender,
String category,
List<String> styles,
Long minPrice,
Long maxPrice,
List<String> brandNames,
List<String> qualityRates,
List<String> sizes,
Long cursorId,
Integer pageSize,
Long userId,
ProductSellingStateType productSellingStateType) {

return jpaQueryFactory
.select(Projections.constructor(GetProductThumbnail.class,
product.id,
product.thumbnailImageUrl,
product.productName,
product.price,
product.discountRate,
product.brandName,
product.qualityRate.stringValue(),
productLike.id.isNotNull()))
.from(product)
.leftJoin(productLike)
.on(product.id.eq(productLike.productId)
.and(productLike.userId.eq(userId)))
.leftJoin(productStyle)
.on(product.id.eq(productStyle.product.id))
.leftJoin(productCategory)
.on(product.id.eq(productCategory.product.id))
.leftJoin(productSellingState)
.on(product.id.eq(productSellingState.productId))
.where(
genderFilter(gender),
categoryFilter(category),
stylesFilter(styles),
priceFilter(minPrice, maxPrice),
brandFilter(brandNames),
qualityFilter(qualityRates),
sizesFilter(sizes),
ltProductId(cursorId),
deletedFilter(),
sellingStateFilter(productSellingStateType))
.orderBy(product.discountRate.desc())
.limit(pageSize)
.fetch()
.stream()
.distinct()
.collect(Collectors.toList());
String gender, String category, List<String> styles, Long minPrice, Long maxPrice, List<String> brandNames,
List<String> qualityRates, List<String> sizes, Long cursorId, Integer pageSize, Long userId) {
return findProducts(gender, category, styles, minPrice, maxPrice, brandNames, qualityRates, sizes, cursorId, pageSize, userId, product.discountRate.desc());
}

@Override
Expand Down
Loading

0 comments on commit 1316e36

Please sign in to comment.