Skip to content

Commit

Permalink
MATE-120 : [FEAT] ValidPageableArgumentResolver 클래스 수정 (#110)
Browse files Browse the repository at this point in the history
* MATE-120 : [FEAT] 메세지 조회 컨트롤러에 @ValidPageable(page = 1) 지정

* MATE-120 : [FEAT] page = 1 지정에 따른 ValidPageableArgumentResolver 클래스 수정

* MATE-120 : [CHORE] page=1 가독성 향상
  • Loading branch information
MisaSohee authored Dec 8, 2024
1 parent 707770a commit cc0136a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ResponseEntity<ApiResponse<GoodsChatRoomResponse>> createGoodsChatRoom(
public ResponseEntity<ApiResponse<PageResponse<GoodsChatMessageResponse>>> 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<GoodsChatMessageResponse> response = goodsChatService.getMessagesForChatRoom(chatRoomId, member.getMemberId(), pageable);
return ResponseEntity.ok(ApiResponse.success(response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ResponseEntity<ApiResponse<MateChatRoomResponse>> joinExistingChatRoom(
public ResponseEntity<ApiResponse<PageResponse<MateChatMessageResponse>>> 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<MateChatMessageResponse> messages = chatRoomService.getChatMessages(chatroomId, member.getMemberId(), pageable);
return ResponseEntity.ok(ApiResponse.success(messages));
Expand Down

0 comments on commit cc0136a

Please sign in to comment.