From a7ab0e011fe9f2a3fcc3d2014f5f6e4b9b2f1b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=8A=B9=EC=A7=84?= Date: Sat, 15 Feb 2025 17:21:34 +0900 Subject: [PATCH 1/2] feat: comment paging result list reverse --- .../main/java/com/example/comment/service/CommentService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/api/show-api/src/main/java/com/example/comment/service/CommentService.java b/app/api/show-api/src/main/java/com/example/comment/service/CommentService.java index a2b9ed70..63aaf3c6 100644 --- a/app/api/show-api/src/main/java/com/example/comment/service/CommentService.java +++ b/app/api/show-api/src/main/java/com/example/comment/service/CommentService.java @@ -2,6 +2,7 @@ import com.example.comment.controller.dto.param.CommentApiParam; import com.example.comment.error.CommentError; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; @@ -69,8 +70,9 @@ public PaginationServiceResponse getComments( .createdAt(DateTimeUtil.formatDateTime(comment.createdAt())) .build(); }) - .toList(); + .collect(Collectors.toList()); + Collections.reverse(commentApiParams); return PaginationServiceResponse.of(commentApiParams, commentsByPagination.hasNext()); } } From 911db9dc7b2fae9ae4d75bff2de7a7efbf46df0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=8A=B9=EC=A7=84?= Date: Sat, 15 Feb 2025 20:19:11 +0900 Subject: [PATCH 2/2] feat: choose cursor id with different method --- .../com/example/comment/controller/CommentController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/api/show-api/src/main/java/com/example/comment/controller/CommentController.java b/app/api/show-api/src/main/java/com/example/comment/controller/CommentController.java index 44fd5202..9424613b 100644 --- a/app/api/show-api/src/main/java/com/example/comment/controller/CommentController.java +++ b/app/api/show-api/src/main/java/com/example/comment/controller/CommentController.java @@ -85,11 +85,11 @@ public SuccessResponse> readComments( CursorApiResponse cursor; if (request.isInverted()) { - cursor = Optional.ofNullable(CursorApiResponse.getFirstElement(commentPagination.data())) + cursor = Optional.ofNullable(CursorApiResponse.getLastElement(commentPagination.data())) .map(element -> CursorApiResponse.toCursorResponse(element.commentId(), element.createdAt())) .orElse(CursorApiResponse.noneCursor()); } else { - cursor = Optional.ofNullable(CursorApiResponse.getLastElement(commentPagination.data())) + cursor = Optional.ofNullable(CursorApiResponse.getFirstElement(commentPagination.data())) .map(element -> CursorApiResponse.toCursorResponse(element.commentId(), element.createdAt())) .orElse(CursorApiResponse.noneCursor()); }