Skip to content

Commit ebc1a73

Browse files
authored
Merge pull request #333 from prgrms-web-devcourse-final-project/develop
배포
2 parents 23e805f + 1629f52 commit ebc1a73

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,7 @@ public ResponseEntity<ApiResponse<List<PollDto>>> getClosedPolls() {
155155
public ResponseEntity<ApiResponse<PollVoteDto>> voteByIndex(@PathVariable Long pollId, @RequestParam int index) {
156156
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
157157
Long memberId = Long.parseLong(authentication.getName());
158-
List<PollOptions> options = pollService.getPollOptions(pollId);
159-
if (index < 1 || index > options.size()) {
160-
throw new ResponseStatusException(org.springframework.http.HttpStatus.BAD_REQUEST, "index가 옵션 범위를 벗어났습니다.");
161-
}
162-
Long pollItemsId = options.get(index - 1).getPollItemsId();
163-
PollVoteDto result = pollService.vote(pollId, pollItemsId, memberId);
158+
PollVoteDto result = pollService.voteByIndex(pollId, index, memberId);
164159
return ResponseEntity.ok(new ApiResponse<>(200, "투표가 성공적으로 완료되었습니다.", result));
165160
}
166161

backend/src/main/java/com/ai/lawyer/domain/poll/service/PollService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public interface PollService {
2828

2929
// ===== 투표 관련 =====
3030
PollVoteDto vote(Long pollId, Long pollItemsId, Long memberId);
31+
PollVoteDto voteByIndex(Long pollId, int index, Long memberId);
3132

3233
// ===== 투표 취소 관련 =====
3334
void cancelVote(Long pollId, Long memberId);

backend/src/main/java/com/ai/lawyer/domain/poll/service/PollServiceImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ public PollVoteDto vote(Long pollId, Long pollItemsId, Long memberId) {
156156
.build();
157157
}
158158

159+
@Override
160+
public PollVoteDto voteByIndex(Long pollId, int index, Long memberId) {
161+
List<PollOptions> options = getPollOptions(pollId);
162+
if (options == null || options.isEmpty()) {
163+
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "투표 항목이 존재하지 않습니다.");
164+
}
165+
if (index < 1 || index > options.size()) {
166+
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "index가 옵션 범위를 벗어났습니다.");
167+
}
168+
Long pollItemsId = options.get(index - 1).getPollItemsId();
169+
return vote(pollId, pollItemsId, memberId);
170+
}
171+
159172
@Override
160173
public PollStaticsResponseDto getPollStatics(Long pollId) {
161174
if (!pollRepository.existsById(pollId)) {

0 commit comments

Comments
 (0)