Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -79,6 +80,7 @@ public List<ItemPreviewResponse> findExhibitionItem(Member member, Long exhibiti
public Page<ItemPreviewResponse> findCategoryItem(Member member, Long categoryId, Pageable pageable) {
Expression<Boolean> isWished = isWishedExpression(member);
BooleanExpression categoryCondition = (categoryId != 0) ? itemCategory.category.id.eq(categoryId) : null;
BooleanExpression saleStatusCondition = item.saleStatus.ne(SaleStatus.STOPPED);

JPAQuery<ItemPreviewResponse> query = queryFactory
.select(Projections.fields(ItemPreviewResponse.class,
Expand All @@ -96,11 +98,12 @@ public Page<ItemPreviewResponse> 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()) {
Expand Down Expand Up @@ -128,11 +131,12 @@ public Page<ItemPreviewResponse> 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);
Expand All @@ -154,6 +158,7 @@ public List<ItemPreviewResponse> findItemsByArtistAndCategory(
Expression<Boolean> 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<ItemPreviewResponse> query = queryFactory
.select(Projections.fields(ItemPreviewResponse.class,
Expand All @@ -170,7 +175,7 @@ public List<ItemPreviewResponse> 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<OrderSpecifier<?>> specifiers = new ArrayList<>(List.of(createOrderSpecifiers(pageable.getSort())));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/data-local.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading