From 45b09359332df4d5a4eeafff8fb3cbacc5c02306 Mon Sep 17 00:00:00 2001 From: king_0417 <73704053+gywns0417@users.noreply.github.com> Date: Mon, 25 Mar 2024 19:01:13 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=AD,=20?= =?UTF-8?q?=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=99=84=EB=A3=8C=20(#239)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 마이페이지 페이지 번호 0부터 시작하도록 수정 * feat: 공지사항 페이지 번호 0부터 시작하도록 수정 --- .../global/exception/ErrorCode.java | 2 +- .../member/presentation/MyPageController.java | 18 +++++++++--------- .../notice/presentation/NoticeController.java | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/balancetalk/global/exception/ErrorCode.java b/src/main/java/balancetalk/global/exception/ErrorCode.java index 120c50074..e7d0aa430 100644 --- a/src/main/java/balancetalk/global/exception/ErrorCode.java +++ b/src/main/java/balancetalk/global/exception/ErrorCode.java @@ -21,7 +21,7 @@ public enum ErrorCode { FILE_SIZE_EXCEEDED(BAD_REQUEST, "파일 크기가 초과되었습니다."), EXCEED_MAX_DEPTH(BAD_REQUEST, "답글에 답글을 달 수 없습니다."), INVALID_REFRESH_TOKEN(BAD_REQUEST, "유효하지 않은 리프레시 토큰입니다."), - PAGE_NUMBER_ZERO(BAD_REQUEST, "페이지 번호는 0보다 커야합니다."), + PAGE_NUMBER_ZERO(BAD_REQUEST, "페이지 번호는 0부터 시작합니다."), PAGE_SIZE_ZERO(BAD_REQUEST, "페이지 사이즈는 0보다 커야합니다."), EXCEED_VALIDATION_LENGTH(BAD_REQUEST, "입력값이 제약 조건에 맞지 않습니다."), AUTHORIZATION_CODE_MISMATCH(BAD_REQUEST, "인증 번호가 일치하지 않습니다."), diff --git a/src/main/java/balancetalk/module/member/presentation/MyPageController.java b/src/main/java/balancetalk/module/member/presentation/MyPageController.java index 10b5ad4ef..f71b33f43 100644 --- a/src/main/java/balancetalk/module/member/presentation/MyPageController.java +++ b/src/main/java/balancetalk/module/member/presentation/MyPageController.java @@ -36,12 +36,12 @@ public class MyPageController { @GetMapping("/history/posts") @Operation(summary = "모든 게시글 조회", description = "해당 회원이 쓴 모든 글을 조회한다.") public Page findAllPosts( - @RequestParam(value = "page", defaultValue = "1") int page, + @RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(required = false, value = "size", defaultValue = "10") int size) { validatePageNumberAndSize(page, size); - Pageable pageable = PageRequest.of(page - 1, size, Sort.by("createdAt").descending()); + Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending()); return postService.findAllByCurrentMember(pageable); } @@ -49,12 +49,12 @@ public Page findAllPosts( @GetMapping("/history/comments") @Operation(summary = "모든 댓글 조회", description = "해당 회원이 쓴 모든 댓글을 조회한다.") public Page findAllComments( - @RequestParam(value = "page", defaultValue = "1") int page, + @RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(required = false, value = "size", defaultValue = "10") int size) { validatePageNumberAndSize(page, size); - Pageable pageable = PageRequest.of(page - 1, size, Sort.by("createdAt").descending()); + Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending()); return commentService.findAllByCurrentMember(pageable); } @@ -62,12 +62,12 @@ public Page findAllComments( @Operation(summary = "투표한 게시글 조회", description = "해당 회원이 투표한 모든 글을 조회한다.") @GetMapping("/history/votedPosts") public Page findAllVotedPosts( - @RequestParam(value = "page", defaultValue = "1") int page, + @RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(required = false, value = "size", defaultValue = "10") int size) { validatePageNumberAndSize(page, size); - Pageable pageable = PageRequest.of(page - 1, size, Sort.by("createdAt").descending()); + Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending()); return postService.findAllVotedByCurrentMember(pageable); } @@ -75,17 +75,17 @@ public Page findAllVotedPosts( @Operation(summary = "북마크한 게시글 조회", description = "해당 회원이 북마크한 모든 글을 조회한다.") @GetMapping("/history/bookmarks") public Page findAllBookmarkedPosts( - @RequestParam(value = "page", defaultValue = "1") int page, + @RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(required = false, value = "size", defaultValue = "10") int size) { validatePageNumberAndSize(page, size); - Pageable pageable = PageRequest.of(page - 1, size, Sort.by("createdAt").descending()); + Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending()); return postService.findAllBookmarkedByCurrentMember(pageable); } private void validatePageNumberAndSize(int page, int size) { - if (page <= 0) { + if (page < 0) { throw new BalanceTalkException(PAGE_NUMBER_ZERO); } if (size <= 0) { diff --git a/src/main/java/balancetalk/module/notice/presentation/NoticeController.java b/src/main/java/balancetalk/module/notice/presentation/NoticeController.java index 09d6ab700..fb92a9d6f 100644 --- a/src/main/java/balancetalk/module/notice/presentation/NoticeController.java +++ b/src/main/java/balancetalk/module/notice/presentation/NoticeController.java @@ -35,17 +35,17 @@ public NoticeResponse createNotice(@Valid @RequestBody final NoticeRequest notic @ResponseStatus(HttpStatus.OK) @GetMapping @Operation(summary = "전체 공지사항 조회" , description = "작성된 모든 공지사항을 페이지네이션을 이용해 조회한다.") - public Page findAllNotices(@RequestParam(value = "page", defaultValue = "1") int page, + public Page findAllNotices(@RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(required = false, value = "size", defaultValue = "13") int size) { - if (page <= 0) { + if (page < 0) { throw new BalanceTalkException(PAGE_NUMBER_ZERO); } if (size <= 0) { throw new BalanceTalkException(PAGE_SIZE_ZERO); } - Pageable pageable = PageRequest.of(page - 1, size); + Pageable pageable = PageRequest.of(page, size); return noticeService.findAllNotices(pageable); }