Skip to content

Commit 31a6ba7

Browse files
committed
feat[post]:투표하기 swagger 추가
1 parent 62ca28f commit 31a6ba7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

backend/src/main/java/com/ai/lawyer/domain/poll/controller/PollController.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ public List<PollDto> getTopOngoingPolls(@RequestParam(defaultValue = "3") int si
132132
return pollService.getTopNPollsByStatus(PollDto.PollStatus.ONGOING, size);
133133
}
134134

135+
@Operation(summary = "index(순번)로 투표하기 - Swagger 편의용")
136+
@PostMapping("/{pollId}/vote-by-index")
137+
public ResponseEntity<?> voteByIndex(@PathVariable Long pollId, @RequestParam int index) {
138+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
139+
Long memberId = Long.parseLong(authentication.getName());
140+
141+
List<PollOptions> options = pollService.getPollOptions(pollId);
142+
if (index < 1 || index > options.size()) {
143+
throw new ResponseStatusException(org.springframework.http.HttpStatus.BAD_REQUEST, "index가 옵션 범위를 벗어났습니다.");
144+
}
145+
Long pollItemsId = options.get(index - 1).getPollItemsId();
146+
return ResponseEntity.ok(pollService.vote(pollId, pollItemsId, memberId));
147+
}
148+
135149
@ExceptionHandler(ResponseStatusException.class)
136150
public ResponseEntity<Object> handleResponseStatusException(ResponseStatusException ex) {
137151
int code = ex.getStatusCode().value();

0 commit comments

Comments
 (0)