diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionRepositoryImpl.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionRepositoryImpl.java index f63bc947d..8e8c305ed 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionRepositoryImpl.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionRepositoryImpl.java @@ -8,7 +8,7 @@ import com.ddang.ddang.auction.configuration.util.AuctionSortConditionConsts; import com.ddang.ddang.auction.domain.Auction; -import com.ddang.ddang.auction.infrastructure.persistence.util.exception.UnsupportedSortConditionException; +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; diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/util/exception/UnsupportedSortConditionException.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/exception/UnsupportedSortConditionException.java similarity index 71% rename from backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/util/exception/UnsupportedSortConditionException.java rename to backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/exception/UnsupportedSortConditionException.java index 752dfaa1a..336072ceb 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/util/exception/UnsupportedSortConditionException.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/exception/UnsupportedSortConditionException.java @@ -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 { diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/util/AuctionSortCondition.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/util/AuctionSortCondition.java deleted file mode 100644 index 775f00dc4..000000000 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/util/AuctionSortCondition.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.ddang.ddang.auction.infrastructure.persistence.util; - -import static com.ddang.ddang.auction.domain.QAuction.auction; -import static org.springframework.data.domain.Sort.Order; - -import com.ddang.ddang.auction.configuration.util.AuctionSortConditionConsts; -import com.ddang.ddang.auction.infrastructure.persistence.util.exception.UnsupportedSortConditionException; -import com.querydsl.core.types.OrderSpecifier; -import com.querydsl.core.types.dsl.ComparableExpressionBase; -import java.util.Arrays; - -public enum AuctionSortCondition { - - ID(AuctionSortConditionConsts.ID, auction.id), - AUCTIONEER_COUNT(AuctionSortConditionConsts.AUCTIONEER_COUNT, auction.auctioneerCount), - CLOSING_TIME(AuctionSortConditionConsts.CLOSING_TINE, auction.closingTime), - RELIABILITY(AuctionSortConditionConsts.RELIABILITY, auction.seller.reliability); - - private final String sortCondition; - private final ComparableExpressionBase sortExpression; - - AuctionSortCondition(final String sortCondition, final ComparableExpressionBase sortExpression) { - this.sortCondition = sortCondition; - this.sortExpression = sortExpression; - } - - public static OrderSpecifier convert(final Order order) { - return Arrays.stream(AuctionSortCondition.values()) - .filter(auctionSortCondition -> isTargetSort(order, auctionSortCondition)) - .findAny() - .map(auctionSortCondition -> convertOrderSpecifier(auctionSortCondition, order)) - .orElseThrow(() -> new UnsupportedSortConditionException("지원하지 않는 정렬 방식입니다.")); - } - - private static boolean isTargetSort(final Order order, final AuctionSortCondition converter) { - return converter.sortCondition.equals(order.getProperty()); - } - - private static OrderSpecifier convertOrderSpecifier( - final AuctionSortCondition sortCondition, - final Order order - ) { - if (order.isDescending()) { - return sortCondition.sortExpression.desc(); - } - - return sortCondition.sortExpression.asc(); - } -} diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/util/AuctionSortConditionTest.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/util/AuctionSortConditionTest.java deleted file mode 100644 index 825444fc4..000000000 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/infrastructure/persistence/util/AuctionSortConditionTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.ddang.ddang.auction.infrastructure.persistence.util; - -import static com.ddang.ddang.auction.domain.QAuction.auction; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import com.ddang.ddang.auction.infrastructure.persistence.util.exception.UnsupportedSortConditionException; -import com.querydsl.core.types.OrderSpecifier; -import java.util.stream.Stream; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.data.domain.Sort.Order; - -class AuctionSortConditionTest { - - @ParameterizedTest(name = "condition이 {0}일 때 {1}을 반환한다.") - @MethodSource("successConvertConditionArguments") - void 유효한_정렬_조건을_전달하면_Querydsl_표현식을_반환한다( - final String sortCondition, - final OrderSpecifier expected - ) { - final OrderSpecifier actual = AuctionSortCondition.convert(Order.by(sortCondition)); - - assertThat(actual).isEqualTo(expected); - } - - private static Stream successConvertConditionArguments() { - return Stream.of( - Arguments.arguments("id", auction.id.asc()), - Arguments.arguments("auctioneerCount", auction.auctioneerCount.asc()), - Arguments.arguments("closingTime", auction.closingTime.asc()), - Arguments.arguments("reliability", auction.seller.reliability.asc()) - ); - } - - @Test - void 유효하지_않은_정렬_조건을_전달하면_예외가_발생한다() { - final String invalidSortCondition = "invalidSortCondition"; - - assertThatThrownBy(() -> AuctionSortCondition.convert(Order.asc(invalidSortCondition))) - .isInstanceOf(UnsupportedSortConditionException.class) - .hasMessageContaining("지원하지 않는 정렬 방식입니다."); - } -}