From cc0136a7ce4fef21453fabe6470a3cc0abc2afa4 Mon Sep 17 00:00:00 2001 From: sohee <144431880+MisaSohee@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:08:03 +0900 Subject: [PATCH] =?UTF-8?q?MATE-120=20:=20[FEAT]=20ValidPageableArgumentRe?= =?UTF-8?q?solver=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=88=98=EC=A0=95=20(#1?= =?UTF-8?q?10)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * MATE-120 : [FEAT] 메세지 조회 컨트롤러에 @ValidPageable(page = 1) 지정 * MATE-120 : [FEAT] page = 1 지정에 따른 ValidPageableArgumentResolver 클래스 수정 * MATE-120 : [CHORE] page=1 가독성 향상 --- .../validator/ValidPageableArgumentResolver.java | 11 ++++++++++- .../goodsChat/controller/GoodsChatRoomController.java | 2 +- .../mateChat/controller/MateChatRoomController.java | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/mate/common/validator/ValidPageableArgumentResolver.java b/src/main/java/com/example/mate/common/validator/ValidPageableArgumentResolver.java index 6ad566cb..5330e867 100644 --- a/src/main/java/com/example/mate/common/validator/ValidPageableArgumentResolver.java +++ b/src/main/java/com/example/mate/common/validator/ValidPageableArgumentResolver.java @@ -27,7 +27,16 @@ public Pageable resolveArgument(MethodParameter methodParameter, // @ValidPageable 어노테이션 확인 ValidPageable validPageable = methodParameter.getParameterAnnotation(ValidPageable.class); - int pageNumber = Math.max(pageable.getPageNumber(), validPageable != null ? validPageable.page() : 0); + // 클라이언트가 page 파라미터를 제공했는지 확인 + String pageParam = webRequest.getParameter("page"); + + // pageParam이 존재하면 pageable.getPageNumber() 사용 + // pageParam이 없고 validPageable이 존재하면 validPageable.page() 사용 + // 둘 다 없으면 0을 사용 + int pageNumber = pageParam != null ? + pageable.getPageNumber() : + (validPageable != null ? validPageable.page() : 0); + int pageSize = pageable.getPageSize() > 0 ? pageable.getPageSize() : validPageable != null ? validPageable.size() : 10; diff --git a/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java b/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java index 727d36e6..75f10e40 100644 --- a/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java +++ b/src/main/java/com/example/mate/domain/goodsChat/controller/GoodsChatRoomController.java @@ -48,7 +48,7 @@ public ResponseEntity> createGoodsChatRoom( public ResponseEntity>> getGoodsChatRoomMessages( @AuthenticationPrincipal AuthMember member, @Parameter(description = "채팅방 ID", required = true) @PathVariable Long chatRoomId, - @Parameter(description = "페이징 정보") @ValidPageable Pageable pageable + @Parameter(description = "페이징 정보") @ValidPageable(page = 1) Pageable pageable ) { PageResponse response = goodsChatService.getMessagesForChatRoom(chatRoomId, member.getMemberId(), pageable); return ResponseEntity.ok(ApiResponse.success(response)); diff --git a/src/main/java/com/example/mate/domain/mateChat/controller/MateChatRoomController.java b/src/main/java/com/example/mate/domain/mateChat/controller/MateChatRoomController.java index 69697ee2..684743ba 100644 --- a/src/main/java/com/example/mate/domain/mateChat/controller/MateChatRoomController.java +++ b/src/main/java/com/example/mate/domain/mateChat/controller/MateChatRoomController.java @@ -62,7 +62,7 @@ public ResponseEntity> joinExistingChatRoom( public ResponseEntity>> getChatMessages( @Parameter(description = "채팅방 ID") @PathVariable Long chatroomId, @AuthenticationPrincipal AuthMember member, - @Parameter(description = "페이지 정보") @ValidPageable(page = 1, size = 20) Pageable pageable + @Parameter(description = "페이지 정보") @ValidPageable(page = 1) Pageable pageable ) { PageResponse messages = chatRoomService.getChatMessages(chatroomId, member.getMemberId(), pageable); return ResponseEntity.ok(ApiResponse.success(messages));