Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

마감 임박순 정렬 쿼리 및 내가 등록한 경매 목록 조회 쿼리 변경 #399

Merged
merged 4 commits into from
Sep 18, 2023
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 @@ -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;
Comment on lines +83 to +92
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메서드 분리하는 거 별로인가요..?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고민을 하기는 했는데...하나마나 엇비슷할 것 같아서 안하기는 했는데 분리할지 조금 더 고민해보겠습니다

}

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
Loading