Skip to content

Commit

Permalink
refactor: #398 마감 임박순 정렬 쿼리 및 내가 등록한 경매 목록 조회 쿼리 변경 (#399)
Browse files Browse the repository at this point in the history
* feat: 마감 임박순 정렬 시 이미 마감된 경매는 후순위로 정렬하는 기능 추가

* chore: 더 이상 사용하지 않는 유틸리티 클래스 삭제

* refactor: 메서드 이름 변경

* fix: 내가 등록한 경매 목록 조회 시 삭제된 경매는 보이지 않도록 쿼리 변경
  • Loading branch information
apptie committed Oct 7, 2023
1 parent a996bc6 commit 40d43a7
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

import com.ddang.ddang.auction.configuration.util.AuctionSortConditionConsts;
import com.ddang.ddang.auction.domain.Auction;
import com.ddang.ddang.auction.infrastructure.persistence.util.AuctionSortCondition;
import com.ddang.ddang.auction.infrastructure.persistence.exception.UnsupportedSortConditionException;
import com.ddang.ddang.auction.presentation.dto.request.ReadAuctionSearchCondition;
import com.ddang.ddang.common.helper.QuerydslSliceHelper;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.core.types.dsl.NumberExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -47,13 +50,51 @@ public Slice<Auction> findAuctionsAllByCondition(
}

private List<OrderSpecifier<?>> calculateOrderSpecifiers(final Pageable pageable) {
final List<OrderSpecifier<?>> orderSpecifiers = new ArrayList<>(convertOrderSpecifiers(pageable));
final List<OrderSpecifier<?>> orderSpecifiers = new ArrayList<>(processOrderSpecifiers(pageable));

orderSpecifiers.add(auction.id.desc());

return orderSpecifiers;
}

private List<OrderSpecifier<?>> processOrderSpecifiers(final Pageable pageable) {
final List<OrderSpecifier<?>> orderSpecifiers = new ArrayList<>();
final Sort sort = pageable.getSort();

for (final Order order : sort) {
if (AuctionSortConditionConsts.ID.equals(order.getProperty())) {
return Collections.emptyList();
}

orderSpecifiers.addAll(processOrderSpecifierByCondition(order));
}

return orderSpecifiers;
}

private List<OrderSpecifier<?>> processOrderSpecifierByCondition(final Order order) {
if (AuctionSortConditionConsts.RELIABILITY.equals(order.getProperty())) {
return List.of(auction.seller.reliability.desc());
}
if (AuctionSortConditionConsts.AUCTIONEER_COUNT.equals(order.getProperty())) {
return List.of(auction.auctioneerCount.desc());
}
if (AuctionSortConditionConsts.CLOSING_TINE.equals(order.getProperty())) {
final LocalDateTime now = LocalDateTime.now();
final NumberExpression<Integer> closingTimeOrder = new CaseBuilder()
.when(auction.closingTime.after(now)).then(1)
.otherwise(2);
final List<OrderSpecifier<?>> orderSpecifiers = new ArrayList<>();

orderSpecifiers.add(closingTimeOrder.asc());
orderSpecifiers.add(auction.closingTime.asc());

return orderSpecifiers;
}

throw new UnsupportedSortConditionException("지원하지 않는 정렬 방식입니다.");
}

private List<BooleanExpression> calculateBooleanExpressions(final ReadAuctionSearchCondition searchCondition) {
final List<BooleanExpression> booleanExpressions = new ArrayList<>();

Expand Down Expand Up @@ -92,21 +133,6 @@ private BooleanExpression convertTitleSearchCondition(final ReadAuctionSearchCon
return auction.title.like("%" + titleSearchCondition + "%");
}

private List<OrderSpecifier<?>> convertOrderSpecifiers(final Pageable pageable) {
final List<OrderSpecifier<?>> orderSpecifiers = new ArrayList<>();
final Sort sort = pageable.getSort();

for (final Order order : sort) {
if (AuctionSortConditionConsts.ID.equals(order.getProperty())) {
return Collections.emptyList();
}

orderSpecifiers.add(AuctionSortCondition.convert(order));
}

return orderSpecifiers;
}

private List<Auction> findAuctionsByIdsAndOrderSpecifiers(
final List<Long> targetIds,
final List<OrderSpecifier<?>> orderSpecifiers
Expand Down Expand Up @@ -144,7 +170,10 @@ public Optional<Auction> findAuctionById(final Long auctionId) {

@Override
public Slice<Auction> findAuctionsAllByUserId(final Long userId, final Pageable pageable) {
final List<BooleanExpression> booleanExpressions = List.of(auction.seller.id.eq(userId));
final List<BooleanExpression> booleanExpressions = List.of(
auction.seller.id.eq(userId),
auction.deleted.isFalse()
);
final List<OrderSpecifier<?>> orderSpecifiers = List.of(auction.id.desc());
final List<Long> findAuctionIds = findAuctionIds(booleanExpressions, orderSpecifiers, pageable);
final List<Auction> findAuctions = findAuctionsByIdsAndOrderSpecifiers(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ddang.ddang.auction.infrastructure.persistence.util.exception;
package com.ddang.ddang.auction.infrastructure.persistence.exception;

public class UnsupportedSortConditionException extends IllegalArgumentException {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
/**
* 사용하는 더미 데이터 (제목 키워드 / ID / 신뢰도 / 경매 참여자 수 / 경매 마감일 / 판매자)
*
* Auction1 : 맥북 / 1L / 4.7d / 2 / 5일 / seller 1
* Auction1 : 맥북 / 1L / 4.7d / 2 / 5일 / seller 1
* Auction2 : 맥북 / 2L / 3.5d / 1 / 4일 뒤 / seller 2
* Auction3 : 맥북 / 3L / 2.1d / 4 / 3일 뒤 / seller 3
* Auction4 : 맥북 / 4L / 5.0d / 7 / 2일 뒤 / seller 4
* Auction5 : 핫식스 / 5L / 1.5d / 4 / 1일 뒤 / seller 5
* Auction6 : 레드불 / 6L / 0.3d / 8 / 2일 / seller 6
* Auction7 : 맥북 / 7L / 4.7d / 3 / 3일 / seller 1
* Auction8 : 맥북 / 8L / 3.5d / 6 / 4일 / seller 2
* Auction9 : 맥북 / 9L / 3.5d / 6 / 4일 / seller 2
* Auction6 : 레드불 / 6L / 0.3d / 8 / 2일 / seller 6
* Auction7 : 맥북 / 7L / 4.7d / 3 / 3일 / seller 1
* Auction8 : 맥북 / 8L / 3.5d / 6 / 4일 / seller 2
* Auction9 : 맥북 / 9L / 3.5d / 6 / 4일 / seller 2
* Auction10 : 맥북 / 10L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction11 : 맥북 / 11L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction12 : 맥북 / 12L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction13 : 맥북 / 13L / 3.5d / 6 / 4일 / seller 2
* Auction13 : 맥북 / 13L / 3.5d / 6 / 4일 / seller 2
* Auction14 : 맥북 / 14L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction15 : 맥북 / 15L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction16 : 맥북 / 16L / 3.5d / 6 / 4일 / seller 2
* Auction16 : 맥북 / 16L / 3.5d / 6 / 4일 / seller 2
*/
@SuppressWarnings("NonAsciiCharacters")
public class AuctionQueryByBidderIdTest extends InitializeCommonAuctionData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
/**
* 사용하는 더미 데이터 (제목 키워드 / ID / 신뢰도 / 경매 참여자 수 / 경매 마감일 / 판매자)
*
* Auction1 : 맥북 / 1L / 4.7d / 2 / 5일 / seller 1
* Auction1 : 맥북 / 1L / 4.7d / 2 / 5일 / seller 1
* Auction2 : 맥북 / 2L / 3.5d / 1 / 4일 뒤 / seller 2
* Auction3 : 맥북 / 3L / 2.1d / 4 / 3일 뒤 / seller 3
* Auction4 : 맥북 / 4L / 5.0d / 7 / 2일 뒤 / seller 4
* Auction5 : 핫식스 / 5L / 1.5d / 4 / 1일 뒤 / seller 5
* Auction6 : 레드불 / 6L / 0.3d / 8 / 2일 / seller 6
* Auction7 : 맥북 / 7L / 4.7d / 3 / 3일 / seller 1
* Auction8 : 맥북 / 8L / 3.5d / 6 / 4일 / seller 2
* Auction9 : 맥북 / 9L / 3.5d / 6 / 4일 / seller 2
* Auction6 : 레드불 / 6L / 0.3d / 8 / 2일 / seller 6
* Auction7 : 맥북 / 7L / 4.7d / 3 / 3일 / seller 1
* Auction8 : 맥북 / 8L / 3.5d / 6 / 4일 / seller 2
* Auction9 : 맥북 / 9L / 3.5d / 6 / 4일 / seller 2
* Auction10 : 맥북 / 10L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction11 : 맥북 / 11L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction12 : 맥북 / 12L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction13 : 맥북 / 13L / 3.5d / 6 / 4일 / seller 2
* Auction13 : 맥북 / 13L / 3.5d / 6 / 4일 / seller 2
* Auction14 : 맥북 / 14L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction15 : 맥북 / 15L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction16 : 맥북 / 16L / 3.5d / 6 / 4일 / seller 2
* Auction16 : 맥북 / 16L / 3.5d / 6 / 4일 / seller 2
*/
@SuppressWarnings("NonAsciiCharacters")
public class AuctionQueryByUserIdTest extends InitializeCommonAuctionData {
Expand All @@ -36,11 +36,11 @@ class 회원이_등록한_경매_목록_조회_테스트 {
/**
* seller 2 기반 경매 목록
*
* Auction16 : 맥북 / 16L / 3.5d / 6 / 4일 / seller 2 Auction15 : 맥북 / 15L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction14 : 맥북 / 14L / 3.5d / 6 / 4일 뒤 / seller 2 Auction13 : 맥북 / 13L / 3.5d / 6 / 4일 / seller 2
* Auction16 : 맥북 / 16L / 3.5d / 6 / 4일 / seller 2 Auction15 : 맥북 / 15L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction14 : 맥북 / 14L / 3.5d / 6 / 4일 뒤 / seller 2 Auction13 : 맥북 / 13L / 3.5d / 6 / 4일 / seller 2
* Auction12 : 맥북 / 12L / 3.5d / 6 / 4일 뒤 / seller 2 Auction11 : 맥북 / 11L / 3.5d / 6 / 4일 뒤 / seller 2
* Auction10 : 맥북 / 10L / 3.5d / 6 / 4일 뒤 / seller 2 Auction9 : 맥북 / 9L / 3.5d / 6 / 4일 / seller 2
* Auction8 : 맥북 / 8L / 3.5d / 6 / 4일 / seller 2 Auction2 : 맥북 / 2L / 3.5d / 1 / 4일 뒤 / seller 2
* Auction10 : 맥북 / 10L / 3.5d / 6 / 4일 뒤 / seller 2 Auction9 : 맥북 / 9L / 3.5d / 6 / 4일 / seller 2
* Auction8 : 맥북 / 8L / 3.5d / 6 / 4일 / seller 2 Auction2 : 맥북 / 2L / 3.5d / 1 / 4일 뒤 / seller 2
*/
@Nested
class Seller2_요청_테스트 {
Expand Down
Loading

0 comments on commit 40d43a7

Please sign in to comment.