11package com .ai .lawyer .domain .post .controller ;
22
33import com .ai .lawyer .domain .poll .dto .PollDto ;
4+ import com .ai .lawyer .domain .poll .dto .PollDto .PollStatus ;
45import com .ai .lawyer .domain .post .dto .*;
56import com .ai .lawyer .domain .post .service .PostService ;
6- import com .ai .lawyer .domain .poll .dto .PollDto ;
77import com .ai .lawyer .domain .member .repositories .MemberRepository ;
88import com .ai .lawyer .global .jwt .TokenProvider ;
99import com .ai .lawyer .global .response .ApiResponse ;
2323
2424import java .util .List ;
2525
26+ import static com .ai .lawyer .domain .poll .entity .Poll .PollStatus .CLOSED ;
27+ import static com .ai .lawyer .domain .poll .entity .Poll .PollStatus .ONGOING ;
28+
2629@ Tag (name = "Post API" , description = "게시글 관련 API" )
2730@ RestController
2831@ RequestMapping ("/api/posts" )
@@ -126,13 +129,17 @@ public ResponseEntity<ApiResponse<PostDto>> getMyPostById(@PathVariable Long pos
126129 return ResponseEntity .ok (new ApiResponse <>(200 , "본인 게시글 단일 조회 성공" , postDto ));
127130 }
128131
129- @ Operation (summary = "본인 게시글 전체 조회" )
130- @ GetMapping ("/my" )
131- public ResponseEntity <ApiResponse <List <PostDto >>> getMyPosts () {
132- Long memberId = AuthUtil .getAuthenticatedMemberId ();
133- List <PostDto > posts = postService .getMyPosts (memberId );
134- return ResponseEntity .ok (new ApiResponse <>(200 , "본인 게시글 전체 조회 성공" , posts ));
135- }
132+ @ Operation (summary = "본인 게시글 전체 조회" )
133+ @ GetMapping ("/my" )
134+ public ResponseEntity <ApiResponse <Page <PostDto >>> getMyPosts (
135+ @ RequestParam (defaultValue = "0" ) int page ,
136+ @ RequestParam (defaultValue = "10" ) int size
137+ ) {
138+ Pageable pageable = PageRequest .of (page , size , org .springframework .data .domain .Sort .by ("updatedAt" ).descending ());
139+ Long memberId = AuthUtil .getAuthenticatedMemberId ();
140+ Page <PostDto > response = postService .getMyPosts (pageable , memberId );
141+ return ResponseEntity .ok (new ApiResponse <>(200 , "본인 게시글 전체 조회 성공" , response ));
142+ }
136143
137144 @ Operation (summary = "게시글+투표 동시 등록" )
138145 @ PostMapping ("/createPost" )
@@ -148,13 +155,10 @@ public ResponseEntity<ApiResponse<PostPageDto>> getPostsPaged(
148155 @ RequestParam (defaultValue = "0" ) int page ,
149156 @ RequestParam (defaultValue = "10" ) int size
150157 ) {
151- Pageable pageable = PageRequest .of (page , size , Sort .by ("createdAt " ).descending ());
158+ Pageable pageable = PageRequest .of (page , size , Sort .by ("updatedAt " ).descending ());
152159 Long memberId = AuthUtil .getCurrentMemberId ();
153- Page <PostDto > posts = postService .getPostsPaged (pageable , memberId );
154- if (posts == null ) {
155- posts = new org .springframework .data .domain .PageImpl <>(java .util .Collections .emptyList (), pageable , 0 );
156- }
157- PostPageDto response = new PostPageDto (posts );
160+ Page <PostDto > pageResult = postService .getPostsPaged (pageable , memberId );
161+ PostPageDto response = new PostPageDto (pageResult );
158162 return ResponseEntity .ok (new ApiResponse <>(200 , "페이징 게시글 조회 성공" , response ));
159163 }
160164
@@ -164,13 +168,10 @@ public ResponseEntity<ApiResponse<PostPageDto>> getOngoingPostsPaged(
164168 @ RequestParam (defaultValue = "0" ) int page ,
165169 @ RequestParam (defaultValue = "10" ) int size
166170 ) {
167- Pageable pageable = PageRequest .of (page , size , Sort .by ("createdAt " ).descending ());
171+ Pageable pageable = PageRequest .of (page , size , Sort .by ("updatedAt " ).descending ());
168172 Long memberId = AuthUtil .getCurrentMemberId ();
169- Page <PostDto > posts = postService .getOngoingPostsPaged (pageable , memberId );
170- if (posts == null ) {
171- posts = new org .springframework .data .domain .PageImpl <>(java .util .Collections .emptyList (), pageable , 0 );
172- }
173- PostPageDto response = new PostPageDto (posts );
173+ Page <PostDto > pageResult = postService .getOngoingPostsPaged (pageable , memberId );
174+ PostPageDto response = new PostPageDto (pageResult );
174175 return ResponseEntity .ok (new ApiResponse <>(200 , "진행중 투표 게시글 페이징 조회 성공" , response ));
175176 }
176177
@@ -180,21 +181,19 @@ public ResponseEntity<ApiResponse<PostPageDto>> getClosedPostsPaged(
180181 @ RequestParam (defaultValue = "0" ) int page ,
181182 @ RequestParam (defaultValue = "10" ) int size
182183 ) {
183- Pageable pageable = PageRequest .of (page , size , Sort .by ("createdAt " ).descending ());
184+ Pageable pageable = PageRequest .of (page , size , Sort .by ("updatedAt " ).descending ());
184185 Long memberId = AuthUtil .getCurrentMemberId ();
185- Page <PostDto > posts = postService .getClosedPostsPaged (pageable , memberId );
186- if (posts == null ) {
187- posts = new org .springframework .data .domain .PageImpl <>(java .util .Collections .emptyList (), pageable , 0 );
188- }
189- PostPageDto response = new PostPageDto (posts );
186+ Page <PostDto > pageResult = postService .getClosedPostsPaged (pageable , memberId );
187+ PostPageDto response = new PostPageDto (pageResult );
190188 return ResponseEntity .ok (new ApiResponse <>(200 , "마감된 투표 게시글 페이징 조회 성공" , response ));
191189 }
192190
193191 @ Operation (summary = "진행중인 투표 Top N 조회" )
194192 @ GetMapping ("/top/ongoingList" )
195193 public ResponseEntity <ApiResponse <List <PostDto >>> getTopNOngoingPolls (@ RequestParam (defaultValue = "3" ) int size ) {
196194 Long memberId = AuthUtil .getCurrentMemberId ();
197- List <PostDto > posts = postService .getTopNPollsByStatus (PollDto .PollStatus .ONGOING , size , memberId );
195+ List <PostDto > posts = postService .getTopNPollsByStatus (
196+ PollStatus .valueOf (ONGOING .name ()), size , memberId );
198197 String message = String .format ("진행중인 투표 Top %d 조회 성공" , size );
199198 return ResponseEntity .ok (new ApiResponse <>(200 , message , posts ));
200199 }
@@ -203,7 +202,8 @@ public ResponseEntity<ApiResponse<List<PostDto>>> getTopNOngoingPolls(@RequestPa
203202 @ GetMapping ("/top/closedList" )
204203 public ResponseEntity <ApiResponse <List <PostDto >>> getTopNClosedPolls (@ RequestParam (defaultValue = "3" ) int size ) {
205204 Long memberId = AuthUtil .getCurrentMemberId ();
206- List <PostDto > posts = postService .getTopNPollsByStatus (PollDto .PollStatus .CLOSED , size , memberId );
205+ List <PostDto > posts = postService .getTopNPollsByStatus (
206+ PollStatus .valueOf (CLOSED .name ()), size , memberId );
207207 String message = String .format ("종료된 투표 Top %d 조회 성공" , size );
208208 return ResponseEntity .ok (new ApiResponse <>(200 , message , posts ));
209209 }
@@ -212,15 +212,17 @@ public ResponseEntity<ApiResponse<List<PostDto>>> getTopNClosedPolls(@RequestPar
212212 @ GetMapping ("/top/ongoing" )
213213 public ResponseEntity <ApiResponse <PostDto >> getTopOngoingPoll () {
214214 Long memberId = AuthUtil .getCurrentMemberId ();
215- PostDto post = postService .getTopPollByStatus (PollDto .PollStatus .ONGOING , memberId );
215+ PostDto post = postService .getTopPollByStatus (
216+ PollStatus .valueOf (ONGOING .name ()), memberId );
216217 return ResponseEntity .ok (new ApiResponse <>(200 , "진행중인 투표 Top 1 조회 성공" , post ));
217218 }
218219
219220 @ Operation (summary = "마감된 투표 Top 1 조회" )
220221 @ GetMapping ("/top/closed" )
221222 public ResponseEntity <ApiResponse <PostDto >> getTopClosedPoll () {
222223 Long memberId = AuthUtil .getCurrentMemberId ();
223- PostDto post = postService .getTopPollByStatus (PollDto .PollStatus .CLOSED , memberId );
224+ PostDto post = postService .getTopPollByStatus (
225+ PollStatus .valueOf (CLOSED .name ()), memberId );
224226 return ResponseEntity .ok (new ApiResponse <>(200 , "마감된 투표 Top 1 조회 성공" , post ));
225227 }
226228
@@ -230,10 +232,10 @@ public ResponseEntity<ApiResponse<PostPageDto>> getMyOngoingPostsPaged(
230232 @ RequestParam (defaultValue = "0" ) int page ,
231233 @ RequestParam (defaultValue = "10" ) int size
232234 ) {
233- Pageable pageable = PageRequest .of (page , size , Sort .by ("createdAt " ).descending ());
235+ Pageable pageable = PageRequest .of (page , size , Sort .by ("updatedAt " ).descending ());
234236 Long memberId = AuthUtil .getAuthenticatedMemberId ();
235- Page <PostDto > posts = postService .getMyOngoingPostsPaged (pageable , memberId );
236- PostPageDto response = new PostPageDto (posts );
237+ Page <PostDto > pageResult = postService .getMyOngoingPostsPaged (pageable , memberId );
238+ PostPageDto response = new PostPageDto (pageResult );
237239 return ResponseEntity .ok (new ApiResponse <>(200 , "내가 참여한 진행중 투표 게시글 페이징 조회 성공" , response ));
238240 }
239241
@@ -243,10 +245,10 @@ public ResponseEntity<ApiResponse<PostPageDto>> getMyClosedPostsPaged(
243245 @ RequestParam (defaultValue = "0" ) int page ,
244246 @ RequestParam (defaultValue = "10" ) int size
245247 ) {
246- Pageable pageable = PageRequest .of (page , size , Sort .by ("createdAt " ).descending ());
248+ Pageable pageable = PageRequest .of (page , size , Sort .by ("updatedAt " ).descending ());
247249 Long memberId = AuthUtil .getAuthenticatedMemberId ();
248- Page <PostDto > posts = postService .getMyClosedPostsPaged (pageable , memberId );
249- PostPageDto response = new PostPageDto (posts );
250+ Page <PostDto > pageResult = postService .getMyClosedPostsPaged (pageable , memberId );
251+ PostPageDto response = new PostPageDto (pageResult );
250252 return ResponseEntity .ok (new ApiResponse <>(200 , "내가 참여한 마감 투표 게시글 페이징 조회 성공" , response ));
251253 }
252254
@@ -256,10 +258,10 @@ public ResponseEntity<ApiResponse<PostPageDto>> getMyVotedPostsPaged(
256258 @ RequestParam (defaultValue = "0" ) int page ,
257259 @ RequestParam (defaultValue = "10" ) int size
258260 ) {
259- Pageable pageable = PageRequest .of (page , size , Sort .by ("createdAt " ).descending ());
261+ Pageable pageable = PageRequest .of (page , size , Sort .by ("updatedAt " ).descending ());
260262 Long memberId = AuthUtil .getAuthenticatedMemberId ();
261- Page <PostDto > posts = postService .getMyVotedPostsPaged (pageable , memberId );
262- PostPageDto response = new PostPageDto (posts );
263+ Page <PostDto > pageResult = postService .getMyVotedPostsPaged (pageable , memberId );
264+ PostPageDto response = new PostPageDto (pageResult );
263265 return ResponseEntity .ok (new ApiResponse <>(200 , "내가 참여한 모든 투표 게시글 페이징 조회 성공" , response ));
264266 }
265267}
0 commit comments