diff --git a/src/main/java/com/promesa/promesa/domain/item/query/ItemQueryRepository.java b/src/main/java/com/promesa/promesa/domain/item/query/ItemQueryRepository.java index a905a4f..dab484b 100644 --- a/src/main/java/com/promesa/promesa/domain/item/query/ItemQueryRepository.java +++ b/src/main/java/com/promesa/promesa/domain/item/query/ItemQueryRepository.java @@ -5,6 +5,7 @@ import com.promesa.promesa.domain.item.domain.Item; import com.promesa.promesa.domain.item.domain.QItem; import com.promesa.promesa.domain.item.domain.QItemImage; + import com.promesa.promesa.domain.item.domain.SaleStatus; import com.promesa.promesa.domain.member.domain.Member; import com.promesa.promesa.domain.wish.domain.TargetType; import com.querydsl.core.types.*; @@ -79,6 +80,7 @@ public List findExhibitionItem(Member member, Long exhibiti public Page findCategoryItem(Member member, Long categoryId, Pageable pageable) { Expression isWished = isWishedExpression(member); BooleanExpression categoryCondition = (categoryId != 0) ? itemCategory.category.id.eq(categoryId) : null; + BooleanExpression saleStatusCondition = item.saleStatus.ne(SaleStatus.STOPPED); JPAQuery query = queryFactory .select(Projections.fields(ItemPreviewResponse.class, @@ -96,11 +98,12 @@ public Page findCategoryItem(Member member, Long categoryId .join(itemCategory.item, item) .join(item.artist, artist) .leftJoin(item.itemImages, itemImage).on(itemImage.isThumbnail.isTrue()) - .where(itemCategory.category.id.eq(categoryId)); + .where(categoryCondition, saleStatusCondition); } else { query.from(item) .join(item.artist, artist) - .leftJoin(item.itemImages, itemImage).on(itemImage.isThumbnail.isTrue()); + .leftJoin(item.itemImages, itemImage).on(itemImage.isThumbnail.isTrue()) + .where(saleStatusCondition); } if (!pageable.getSort().isEmpty()) { @@ -128,11 +131,12 @@ public Page findCategoryItem(Member member, Long categoryId .select(item.count()) .from(itemCategory) .join(itemCategory.item, item) - .where(itemCategory.category.id.eq(categoryId)); + .where(categoryCondition, saleStatusCondition); } else { countQuery = queryFactory .select(item.count()) - .from(item); + .from(item) + .where(saleStatusCondition); } return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchOne); @@ -154,6 +158,7 @@ public List findItemsByArtistAndCategory( Expression isWished = isWishedExpression(member); BooleanExpression categoryCondition = (categoryId != 0) ? itemCategory.category.id.eq(categoryId) : null; BooleanExpression artistCondition = artist.id.eq(artistId); + BooleanExpression saleStatusCondition = item.saleStatus.ne(SaleStatus.STOPPED); JPAQuery query = queryFactory .select(Projections.fields(ItemPreviewResponse.class, @@ -170,7 +175,7 @@ public List findItemsByArtistAndCategory( .join(itemCategory.item, item) .join(item.artist, artist) .leftJoin(item.itemImages, itemImage).on(itemImage.isThumbnail.isTrue()) - .where(artistCondition, categoryCondition); + .where(artistCondition, categoryCondition, saleStatusCondition); if (!pageable.getSort().isEmpty()) { List> specifiers = new ArrayList<>(List.of(createOrderSpecifiers(pageable.getSort()))); diff --git a/src/main/resources/data-local.sql b/src/main/resources/data-local.sql index a3bfec0..9f1cd59 100644 --- a/src/main/resources/data-local.sql +++ b/src/main/resources/data-local.sql @@ -148,7 +148,7 @@ INSERT INTO item ( depth, artist_id ) VALUES - (1, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), '빈티지 블랙 높은잔 세트', 15000, 'ON_SALE', 11, 1, 3.5, 1, 3.5, 'PRD001', 10, 20, 30, 2), + (1, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), '빈티지 블랙 높은잔 세트', 15000, 'STOPPED', 11, 1, 3.5, 1, 3.5, 'PRD001', 10, 20, 30, 2), (2, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), '작품 2', 20000, 'ON_SALE', 12, 2, 4.0, 2, 8.0, 'PRD002', 10, 20, 30, 3), (3, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), '작품 3', 25000, 'ON_SALE', 13, 0, 3.0, 0, 0.0, 'PRD003', 10, 20, 30, 4), (4, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP(), '작품 4', 30000, 'ON_SALE', 14, 1, NULL, 1, 0.0, 'PRD004', 10, 20, 30, 5),