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

cursor 관련 수정 #116 #120

Merged
merged 3 commits into from
Nov 19, 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
2 changes: 1 addition & 1 deletion src/main/java/io/oduck/api/domain/anime/dto/AnimeReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static class PatchSeriesIdReq{
@Getter
@AllArgsConstructor
public enum Sort {
LATEST("title"),
LATEST("id"),
REVIEW_COUNT("reviewCount"),
SCORE("starRatingScoreTotal");

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/oduck/api/domain/anime/dto/AnimeRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public SearchResult(Long id, String title, String thumbnail, Long starRatingScor

@Override
public String bringCursor(String property) {
return title;
return id.toString();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,28 @@ private BooleanExpression cursorCondition(String cursor, Pageable pageable) {
return null;
}

if(isParsableAsLong(cursor) == false) {
return null;
}

Long id = Long.parseLong(cursor);

List<Sort.Order> orders = pageable.getSort().get().collect(Collectors.toList());
Direction direction = orders.get(0).getDirection();

if (direction == Direction.ASC) {
return anime.title.gt(cursor);
return anime.id.gt(id);
}else{
return anime.title.lt(cursor);
return anime.id.lt(id);
}
}

private boolean isParsableAsLong(String cursor) {
try {
Long.parseLong(cursor);
return true;
} catch (NumberFormatException e) {
return false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/oduck/api/e2e/anime/AnimeControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void getAnimes() throws Exception {
.description("Quarter의 리스트. Quarters가 null이거나 empty하지 않으면 자동으로 <최신 년도+분기>로 예상하고 로직을 수행합니다. 예를 들어 2023년에 클라이언트가 Q1으로 요청하면, 서버에 Q1만 보내도 자동으로 2023년은 내부 로직으로 계산합니다."),
parameterWithName("cursor")
.optional()
.description("마지막 아이템 제목")
.description("마지막 아이템의 고유 식별자")
),
responseFields(
fieldWithPath("items")
Expand All @@ -139,7 +139,7 @@ void getAnimes() throws Exception {
.description("마지막 페이지 여부"),
fieldWithPath("cursor")
.type(JsonFieldType.STRING)
.description("마지막 아이템의 제목, 다음 페이지 요청시 cursor로 사용. 다음 페이지가 없다면 \"\"")
.description("마지막 아이템의 고유 식별자, 다음 페이지 요청시 cursor로 사용. 다음 페이지가 없다면 \"\". 숫자가 아닌 형태가 온다면 입력하지 않는 것으로 처리된다.")
)
));

Expand Down