99import com .ai .lawyer .domain .poll .service .PollService ;
1010import com .ai .lawyer .domain .post .dto .PostDetailDto ;
1111import com .ai .lawyer .domain .post .service .PostService ;
12+ import com .ai .lawyer .global .response .ApiResponse ;
1213import io .swagger .v3 .oas .annotations .Operation ;
1314import io .swagger .v3 .oas .annotations .tags .Tag ;
1415import lombok .RequiredArgsConstructor ;
@@ -32,52 +33,60 @@ public class PollController {
3233
3334 @ Operation (summary = "투표 단일 조회" )
3435 @ GetMapping ("/{pollId}" )
35- public PollDto getPoll (@ PathVariable Long pollId ) {
36- return pollService .getPoll (pollId );
36+ public ResponseEntity <ApiResponse <PollDto >> getPoll (@ PathVariable Long pollId ) {
37+ PollDto poll = pollService .getPoll (pollId );
38+ return ResponseEntity .ok (new ApiResponse <>(200 , "투표 단일 조회 성공" , poll ));
3739 }
3840
3941 @ Operation (summary = "투표 옵션 목록 조회" )
4042 @ GetMapping ("/{pollId}/options" )
41- public List <PollOptions > getPollOptions (@ PathVariable Long pollId ) {
42- return pollService .getPollOptions (pollId );
43+ public ResponseEntity <ApiResponse <List <PollOptions >>> getPollOptions (@ PathVariable Long pollId ) {
44+ List <PollOptions > options = pollService .getPollOptions (pollId );
45+ return ResponseEntity .ok (new ApiResponse <>(200 , "투표 옵션 목록 조회 성공" , options ));
4346 }
4447
4548 @ Operation (summary = "투표하기" )
4649 @ PostMapping ("/{pollId}/vote" )
47- public ResponseEntity <? > vote (@ PathVariable Long pollId , @ RequestParam Long pollItemsId ) {
50+ public ResponseEntity <ApiResponse < PollVoteDto > > vote (@ PathVariable Long pollId , @ RequestParam Long pollItemsId ) {
4851 Authentication authentication = SecurityContextHolder .getContext ().getAuthentication ();
4952 Long memberId = Long .parseLong (authentication .getName ());
50- return ResponseEntity .ok (pollService .vote (pollId , pollItemsId , memberId ));
53+ PollVoteDto result = pollService .vote (pollId , pollItemsId , memberId );
54+ return ResponseEntity .ok (new ApiResponse <>(200 , "투표가 성공적으로 완료되었습니다." , result ));
5155 }
5256
5357 @ Operation (summary = "투표 통계 조회" )
5458 @ GetMapping ("/{pollId}/statics" )
55- public List <PollStatics > getPollStatics (@ PathVariable Long pollId ) {
56- return pollService .getPollStatics (pollId );
59+ public ResponseEntity <ApiResponse <List <PollStatics >>> getPollStatics (@ PathVariable Long pollId ) {
60+ List <PollStatics > statics = pollService .getPollStatics (pollId );
61+ return ResponseEntity .ok (new ApiResponse <>(200 , "투표 통계 조회 성공" , statics ));
5762 }
5863
5964 @ Operation (summary = "투표 종료" )
6065 @ PutMapping ("/{pollId}/close" )
61- public void closePoll (@ PathVariable Long pollId ) {
66+ public ResponseEntity < ApiResponse < Void >> closePoll (@ PathVariable Long pollId ) {
6267 pollService .closePoll (pollId );
68+ return ResponseEntity .ok (new ApiResponse <>(200 , "투표가 종료되었습니다." , null ));
6369 }
6470
6571 @ Operation (summary = "투표 삭제" )
6672 @ DeleteMapping ("/{pollId}" )
67- public void deletePoll (@ PathVariable Long pollId ) {
73+ public ResponseEntity < ApiResponse < Void >> deletePoll (@ PathVariable Long pollId ) {
6874 pollService .deletePoll (pollId );
75+ return ResponseEntity .ok (new ApiResponse <>(200 , "투표가 삭제되었습니다." , null ));
6976 }
7077
7178 @ Operation (summary = "진행중인 투표 Top 1 조회" )
7279 @ GetMapping ("/top/ongoing" )
73- public PollDto getTopOngoingPoll () {
74- return pollService .getTopPollByStatus (PollDto .PollStatus .ONGOING );
80+ public ResponseEntity <ApiResponse <PollDto >> getTopOngoingPoll () {
81+ PollDto poll = pollService .getTopPollByStatus (PollDto .PollStatus .ONGOING );
82+ return ResponseEntity .ok (new ApiResponse <>(200 , "진행중인 투표 Top 1 조회 성공" , poll ));
7583 }
7684
7785 @ Operation (summary = "종료된 투표 Top 1 조회" )
7886 @ GetMapping ("/top/closed" )
79- public PollDto getTopClosedPoll () {
80- return pollService .getTopPollByStatus (PollDto .PollStatus .CLOSED );
87+ public ResponseEntity <ApiResponse <PollDto >> getTopClosedPoll () {
88+ PollDto poll = pollService .getTopPollByStatus (PollDto .PollStatus .CLOSED );
89+ return ResponseEntity .ok (new ApiResponse <>(200 , "종료된 투표 Top 1 조회 성공" , poll ));
8190 }
8291
8392// @Operation(summary = "진행중인 투표 상세 조회")
@@ -96,63 +105,68 @@ public PollDto getTopClosedPoll() {
96105
97106 @ Operation (summary = "투표 생성" )
98107 @ PostMapping ("" )
99- public ResponseEntity <? > createPoll (@ RequestBody PollCreateDto pollCreateDto ) {
108+ public ResponseEntity <ApiResponse < PollDto > > createPoll (@ RequestBody PollCreateDto pollCreateDto ) {
100109 Authentication authentication = SecurityContextHolder .getContext ().getAuthentication ();
101110 Long memberId = Long .parseLong (authentication .getName ());
102- return ResponseEntity .ok (pollService .createPoll (pollCreateDto , memberId ));
111+ PollDto created = pollService .createPoll (pollCreateDto , memberId );
112+ return ResponseEntity .ok (new ApiResponse <>(201 , "투표가 생성되었습니다." , created ));
103113 }
104114
105115 @ Operation (summary = "투표 수정" )
106116 @ PutMapping ("/{pollId}" )
107- public PollDto updatePoll (@ PathVariable Long pollId , @ RequestBody com .ai .lawyer .domain .poll .dto .PollUpdateDto pollUpdateDto ) {
108- return pollService .updatePoll (pollId , pollUpdateDto );
117+ public ResponseEntity <ApiResponse <PollDto >> updatePoll (@ PathVariable Long pollId , @ RequestBody com .ai .lawyer .domain .poll .dto .PollUpdateDto pollUpdateDto ) {
118+ PollDto updated = pollService .updatePoll (pollId , pollUpdateDto );
119+ return ResponseEntity .ok (new ApiResponse <>(200 , "투표가 수정되었습니다." , updated ));
109120 }
110121
111122 @ Operation (summary = "진행중인 투표 전체 목록 조회" )
112123 @ GetMapping ("/ongoing" )
113- public List <PollDto > getOngoingPolls () {
114- return pollService .getPollsByStatus (PollDto .PollStatus .ONGOING );
124+ public ResponseEntity <ApiResponse <List <PollDto >>> getOngoingPolls () {
125+ List <PollDto > polls = pollService .getPollsByStatus (PollDto .PollStatus .ONGOING );
126+ return ResponseEntity .ok (new ApiResponse <>(200 , "진행중인 투표 전체 목록 조회 성공" , polls ));
115127 }
116128
117129 @ Operation (summary = "종료된 투표 전체 목록 조회" )
118130 @ GetMapping ("/closed" )
119- public List <PollDto > getClosedPolls () {
120- return pollService .getPollsByStatus (PollDto .PollStatus .CLOSED );
131+ public ResponseEntity <ApiResponse <List <PollDto >>> getClosedPolls () {
132+ List <PollDto > polls = pollService .getPollsByStatus (PollDto .PollStatus .CLOSED );
133+ return ResponseEntity .ok (new ApiResponse <>(200 , "종료된 투표 전체 목록 조회 성공" , polls ));
121134 }
122135
123136 @ Operation (summary = "종료된 투표 Top N 조회" )
124137 @ GetMapping ("/top/closed-list" ) //검색조건 : pi/polls/top/closed-list?size=3
125- public List <PollDto > getTopClosedPolls (@ RequestParam (defaultValue = "3" ) int size ) {
126- return pollService .getTopNPollsByStatus (PollDto .PollStatus .CLOSED , size );
138+ public ResponseEntity <ApiResponse <List <PollDto >>> getTopClosedPolls (@ RequestParam (defaultValue = "3" ) int size ) {
139+ List <PollDto > polls = pollService .getTopNPollsByStatus (PollDto .PollStatus .CLOSED , size );
140+ String message = String .format ("종료된 투표 Top %d 조회 성공" , size );
141+ return ResponseEntity .ok (new ApiResponse <>(200 , message , polls ));
127142 }
128143
129144 @ Operation (summary = "진행중인 투표 Top N 조회" )
130145 @ GetMapping ("/top/ongoing-list" ) //검색조건 : api/polls/top/ongoing-list?size=3
131- public List <PollDto > getTopOngoingPolls (@ RequestParam (defaultValue = "3" ) int size ) {
132- return pollService .getTopNPollsByStatus (PollDto .PollStatus .ONGOING , size );
146+ public ResponseEntity <ApiResponse <List <PollDto >>> getTopOngoingPolls (@ RequestParam (defaultValue = "3" ) int size ) {
147+ List <PollDto > polls = pollService .getTopNPollsByStatus (PollDto .PollStatus .ONGOING , size );
148+ String message = String .format ("진행중인 투표 Top %d 조회 성공" , size );
149+ return ResponseEntity .ok (new ApiResponse <>(200 , message , polls ));
133150 }
134151
135152 @ Operation (summary = "index(순번)로 투표하기 - Swagger 편의용" )
136153 @ PostMapping ("/{pollId}/vote-by-index" )
137- public ResponseEntity <? > voteByIndex (@ PathVariable Long pollId , @ RequestParam int index ) {
154+ public ResponseEntity <ApiResponse < PollVoteDto > > voteByIndex (@ PathVariable Long pollId , @ RequestParam int index ) {
138155 Authentication authentication = SecurityContextHolder .getContext ().getAuthentication ();
139156 Long memberId = Long .parseLong (authentication .getName ());
140-
141157 List <PollOptions > options = pollService .getPollOptions (pollId );
142158 if (index < 1 || index > options .size ()) {
143159 throw new ResponseStatusException (org .springframework .http .HttpStatus .BAD_REQUEST , "index가 옵션 범위를 벗어났습니다." );
144160 }
145161 Long pollItemsId = options .get (index - 1 ).getPollItemsId ();
146- return ResponseEntity .ok (pollService .vote (pollId , pollItemsId , memberId ));
162+ PollVoteDto result = pollService .vote (pollId , pollItemsId , memberId );
163+ return ResponseEntity .ok (new ApiResponse <>(200 , "투표가 성공적으로 완료되었습니다." , result ));
147164 }
148165
149166 @ ExceptionHandler (ResponseStatusException .class )
150- public ResponseEntity <Object > handleResponseStatusException (ResponseStatusException ex ) {
167+ public ResponseEntity <ApiResponse < Void > > handleResponseStatusException (ResponseStatusException ex ) {
151168 int code = ex .getStatusCode ().value ();
152169 String message = ex .getReason ();
153- return ResponseEntity .status (code ).body (new java .util .HashMap <String , Object >() {{
154- put ("code" , code );
155- put ("message" , message );
156- }});
170+ return ResponseEntity .status (code ).body (new ApiResponse <>(code , message , null ));
157171 }
158172}
0 commit comments