Skip to content

Commit

Permalink
fix: bug on like API (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
mushroom1324 authored Sep 18, 2024
1 parent 6cfb02b commit f7b185b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ Page<GetProductThumbnail> findHighestDiscountProducts(

List<GetProductByClothingSalesDto> findProductDtoByClothingSalesId(long clothingSalesId);

List<Product> findByProductSellingStateType(ProductStateType productStateType);

List<GetBrandList> getBrandList();

List<Product> findRecommendation(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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.Expressions;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQuery;
Expand Down Expand Up @@ -69,8 +68,6 @@ private Page<GetProductThumbnail> findProducts(
.on(product.id.eq(productCategory.product.id))
.leftJoin(productMaterial)
.on(product.id.eq(productMaterial.product.id))
.leftJoin(productState)
.on(product.id.eq(productState.productId))
.where(
keywordFilter(productFilter.keyword()),
genderFilter(productFilter.gender()),
Expand All @@ -82,7 +79,7 @@ private Page<GetProductThumbnail> findProducts(
sizesFilter(productFilter.sizes()),
materialsFilter(productFilter.materials()),
deletedFilter(),
sellingStateFilter(ProductStateType.SELLING))
sellingStateFilter())
.distinct()
.orderBy(orderBy);

Expand Down Expand Up @@ -138,7 +135,8 @@ public Page<GetProductThumbnail> findLikedProducts(String category, Long userId,
.where(
likeFilter(userId),
categoryFilter(category, false),
deletedFilter())
deletedFilter(),
sellingStateFilter())
.distinct()
.orderBy(productLike.id.desc());
long total = query.stream().count();
Expand Down Expand Up @@ -257,24 +255,8 @@ private BooleanExpression deletedFilter() {
return product.isDeleted.eq(false);
}

private BooleanExpression sellingStateFilter(ProductStateType productStateType) {
if (productStateType == null) {
return null;
}

QProductState subProductState = new QProductState("subProductState");

return productState.id.in(
JPAExpressions
.select(subProductState.id)
.from(subProductState)
.where(subProductState.id.in(
JPAExpressions
.select(productState.id.max())
.from(productState)
.groupBy(productState.productId)
).and(subProductState.productStateType.eq(ProductStateType.SELLING)))
);
private BooleanExpression sellingStateFilter() {
return product.productState.eq(ProductStateType.SELLING);
}

private BooleanExpression stylesFilter(List<String> styles) {
Expand Down Expand Up @@ -311,13 +293,11 @@ public Page<GetProductThumbnail> findMainPageRecommendation(Pageable pageable, L
.on(product.id.eq(productStyle.product.id))
.leftJoin(productCategory)
.on(product.id.eq(productCategory.product.id))
.leftJoin(productState)
.on(product.id.eq(productState.productId))
.where(
genderFilter(gender),
subCategoryFilter(subCategories),
deletedFilter(),
sellingStateFilter(ProductStateType.SELLING))
sellingStateFilter())
.distinct()
.orderBy(product.id.desc());
long total = query.stream().count();
Expand Down Expand Up @@ -348,16 +328,6 @@ public List<GetProductByClothingSalesDto> findProductDtoByClothingSalesId(long c
.fetch();
}

@Override
public List<Product> findByProductSellingStateType(ProductStateType productStateType) {
return jpaQueryFactory
.selectFrom(product)
.leftJoin(productState)
.on(product.id.eq(productState.productId))
.where(sellingStateFilter(productStateType))
.fetch();
}

@Override
public List<GetBrandList> getBrandList() {
return jpaQueryFactory
Expand Down

0 comments on commit f7b185b

Please sign in to comment.