1212import com .example .cherrydan .common .exception .ErrorMessage ;
1313import com .example .cherrydan .oauth .security .jwt .UserDetailsImpl ;
1414import lombok .RequiredArgsConstructor ;
15+ import org .springframework .data .domain .PageRequest ;
1516import org .springframework .data .domain .Pageable ;
17+ import org .springframework .data .domain .Sort ;
1618import org .springframework .http .ResponseEntity ;
1719import org .springframework .security .core .annotation .AuthenticationPrincipal ;
1820import org .springframework .web .bind .annotation .*;
@@ -50,22 +52,28 @@ public ResponseEntity<ApiResponse<EmptyResponse>> cancelBookmark(
5052
5153 @ Operation (
5254 summary = "북마크 목록 조회" ,
53- description = "case 파라미터(open/closed )로 북마크 목록을 조회합니다. open : 기간 남은 북마크, closed : 기간 지난 북마크"
55+ description = "case 파라미터(likedOpen/likedClosed )로 북마크 목록을 조회합니다. likedOpen : 기간 남은 북마크, likedClosed : 기간 지난 북마크"
5456 )
5557 @ GetMapping ("/bookmarks" )
5658 public ResponseEntity <ApiResponse <PageListResponseDTO <BookmarkResponseDTO >>> getBookmarksByCase (
57- @ Parameter (description = "북마크 케이스 (open: 기간 남은 북마크, closed: 기간 지난 북마크)" , required = false )
58- @ RequestParam (value = "case" , defaultValue = "open" ) String caseParam ,
59- @ AuthenticationPrincipal UserDetailsImpl currentUser ,
60- Pageable pageable
59+ @ Parameter (description = "북마크 케이스 (likedOpen: 기간 남은 북마크, likedClosed: 기간 지난 북마크)" )
60+ @ RequestParam (value = "case" , defaultValue = "likedOpen" ) String caseParam ,
61+ @ Parameter (description = "정렬 기준 createdAt" , example = "createdAt" )
62+ @ RequestParam (defaultValue = "createdAt" ) String sort ,
63+ @ Parameter (description = "페이지 번호" , example = "0" )
64+ @ RequestParam (defaultValue = "0" ) int page ,
65+ @ Parameter (description = "페이지 크기" , example = "20" )
66+ @ RequestParam (defaultValue = "20" ) int size ,
67+ @ AuthenticationPrincipal UserDetailsImpl currentUser
6168 ) {
6269 BookmarkCase bookmarkCase ;
6370 try {
6471 bookmarkCase = BookmarkCase .fromCode (caseParam .trim ());
6572 } catch (IllegalArgumentException e ) {
6673 throw new CampaignException (ErrorMessage .CAMPAIGN_STATUS_INVALID );
6774 }
68-
75+
76+ Pageable pageable = createPageable (page , size , sort );
6977 PageListResponseDTO <BookmarkResponseDTO > result = bookmarkService .getBookmarksByCase (currentUser .getId (), bookmarkCase , pageable );
7078 String message = bookmarkCase == BookmarkCase .LIKED_OPEN ? "신청 가능한 공고 목록 조회 성공" : "신청 마감된 공고 목록 조회 성공" ;
7179 return ResponseEntity .ok (ApiResponse .success (message , result ));
@@ -80,4 +88,8 @@ public ResponseEntity<ApiResponse<EmptyResponse>> deleteBookmark(
8088 bookmarkService .deleteBookmark (currentUser .getId (), request );
8189 return ResponseEntity .ok (ApiResponse .success ("북마크 삭제 성공" ));
8290 }
91+
92+ private Pageable createPageable (int page , int size , String sort ) {
93+ return PageRequest .of (page , size , Sort .by (Sort .Direction .DESC , sort ));
94+ }
8395}
0 commit comments