Skip to content

Commit

Permalink
fix: 최신순 정렬에 id 기준 내림차순 정렬 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
70825 committed Jun 7, 2024
1 parent 9ec1ed0 commit ae206c0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/test/java/com/funeat/fixture/PageFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("NonAsciiCharacters")
public class PageFixture {
Expand All @@ -18,7 +22,7 @@ public class PageFixture {
public static final String 평점_오름차순 = "rating,asc";
public static final String 평점_내림차순 = "rating,desc";
public static final String 과거순 = "createdAt,asc";
public static final String 최신순 = "createdAt,desc";
public static final String 최신순 = "createdAt,desc,id,desc";
public static final String 아이디_내림차순 = "id,desc";

public static final Long PAGE_SIZE = 10L;
Expand All @@ -36,10 +40,14 @@ public class PageFixture {

public static PageRequest 페이지요청_생성(final int page, final int size, final String sort) {
final String[] splitSort = sort.split(",");
final String order = splitSort[0];
final Direction direction = Direction.fromString(splitSort[1]);

return PageRequest.of(page, size, Sort.by(direction, order));
final List<Order> orders = new ArrayList<>();
for (int idx = 0; idx < splitSort.length; idx += 2) {
final String property = splitSort[idx];
final Direction direction = Direction.fromString(splitSort[idx + 1]);
orders.add(new Order(direction, property));
}

return PageRequest.of(page, size, Sort.by(orders));
}

public static PageDto 응답_페이지_생성(final Long totalDataCount, final Long totalPages, final boolean firstPage,
Expand Down

0 comments on commit ae206c0

Please sign in to comment.