diff --git a/backend/src/main/java/middle_point_search/backend/common/exception/errorCode/UserErrorCode.java b/backend/src/main/java/middle_point_search/backend/common/exception/errorCode/UserErrorCode.java index 738a1358..f801a6fa 100644 --- a/backend/src/main/java/middle_point_search/backend/common/exception/errorCode/UserErrorCode.java +++ b/backend/src/main/java/middle_point_search/backend/common/exception/errorCode/UserErrorCode.java @@ -24,7 +24,7 @@ public enum UserErrorCode implements ErrorCode { VOTE_NOT_FOUND(HttpStatus.NOT_FOUND, "투표를 한 적이 없습니다."), VOTE_ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, "생성된 투표방이 없습니다."), - CANDIDATE_NOT_FOUND(HttpStatus.NOT_FOUND, "투표 후보가 아닙니다."), + CANDIDATE_NOT_FOUND(HttpStatus.BAD_REQUEST, "투표 후보가 아닙니다."), ALREADY_VOTED(HttpStatus.CONFLICT, "이미 투표를 하였습니다."), DUPLICATE_VOTE_ROOM(HttpStatus.CONFLICT, "이미 투표방이 존재합니다."), diff --git a/backend/src/main/java/middle_point_search/backend/domains/placeVoteRoom/controller/PlaceVoteRoomController.java b/backend/src/main/java/middle_point_search/backend/domains/placeVoteRoom/controller/PlaceVoteRoomController.java index 2eb746fa..9bbe2d85 100644 --- a/backend/src/main/java/middle_point_search/backend/domains/placeVoteRoom/controller/PlaceVoteRoomController.java +++ b/backend/src/main/java/middle_point_search/backend/domains/placeVoteRoom/controller/PlaceVoteRoomController.java @@ -225,6 +225,11 @@ public ResponseEntity> placeVoteRoomResultGe responseCode = "200", description = "성공" ), + @ApiResponse( + responseCode = "400", + description = "투표 후보가 아닙니다.", + content = @Content(schema = @Schema(implementation = ErrorResponse.class)) + ), @ApiResponse( responseCode = "401", description = "인증에 실패하였습니다.", @@ -245,11 +250,6 @@ public ResponseEntity> placeVoteRoomResultGe description = "생성된 투표방이 없습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)) ), - @ApiResponse( - responseCode = "404", - description = "투표 후보가 아닙니다.", - content = @Content(schema = @Schema(implementation = ErrorResponse.class)) - ), @ApiResponse( responseCode = "409", description = "이미 투표를 하였습니다.", @@ -288,6 +288,11 @@ public ResponseEntity vote(@RequestBody @Valid PlaceVoteRequest request) { responseCode = "200", description = "성공" ), + @ApiResponse( + responseCode = "400", + description = "투표 후보가 아닙니다.", + content = @Content(schema = @Schema(implementation = ErrorResponse.class)) + ), @ApiResponse( responseCode = "401", description = "인증에 실패하였습니다.", @@ -308,11 +313,6 @@ public ResponseEntity vote(@RequestBody @Valid PlaceVoteRequest request) { description = "생성된 투표방이 없습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)) ), - @ApiResponse( - responseCode = "404", - description = "투표 후보가 아닙니다.", - content = @Content(schema = @Schema(implementation = ErrorResponse.class)) - ), @ApiResponse( responseCode = "404", description = "투표를 한 적이 없습니다.", diff --git a/backend/src/main/java/middle_point_search/backend/domains/timeVoteRoom/controller/TimeVoteRoomController.java b/backend/src/main/java/middle_point_search/backend/domains/timeVoteRoom/controller/TimeVoteRoomController.java index 1a136855..539ec349 100644 --- a/backend/src/main/java/middle_point_search/backend/domains/timeVoteRoom/controller/TimeVoteRoomController.java +++ b/backend/src/main/java/middle_point_search/backend/domains/timeVoteRoom/controller/TimeVoteRoomController.java @@ -170,6 +170,11 @@ public ResponseEntity> timeVoteRoomRecr responseCode = "200", description = "성공" ), + @ApiResponse( + responseCode = "400", + description = "투표 후보가 아닙니다.", + content = @Content(schema = @Schema(implementation = ErrorResponse.class)) + ), @ApiResponse( responseCode = "401", description = "인증에 실패하였습니다.", @@ -190,7 +195,6 @@ public ResponseEntity> timeVoteRoomRecr description = "생성된 투표방이 없습니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)) ), - @ApiResponse( responseCode = "409", description = "이미 투표를 하였습니다.", @@ -230,6 +234,11 @@ public ResponseEntity vote(@RequestBody @Valid TimeVoteRoomVoteRequest reques responseCode = "200", description = "성공" ), + @ApiResponse( + responseCode = "400", + description = "투표 후보가 아닙니다.", + content = @Content(schema = @Schema(implementation = ErrorResponse.class)) + ), @ApiResponse( responseCode = "401", description = "인증에 실패하였습니다.", diff --git a/backend/src/main/java/middle_point_search/backend/domains/timeVoteRoom/service/TimeVoteRoomService.java b/backend/src/main/java/middle_point_search/backend/domains/timeVoteRoom/service/TimeVoteRoomService.java index 74528c22..5b1de03a 100644 --- a/backend/src/main/java/middle_point_search/backend/domains/timeVoteRoom/service/TimeVoteRoomService.java +++ b/backend/src/main/java/middle_point_search/backend/domains/timeVoteRoom/service/TimeVoteRoomService.java @@ -1,25 +1,31 @@ package middle_point_search.backend.domains.timeVoteRoom.service; +import static middle_point_search.backend.common.exception.errorCode.UserErrorCode.*; +import static middle_point_search.backend.domains.timeVoteRoom.dto.TimeVoteRoomDTO.*; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import lombok.RequiredArgsConstructor; import middle_point_search.backend.common.exception.CustomException; +import middle_point_search.backend.domains.member.domain.Member; +import middle_point_search.backend.domains.room.domain.Room; import middle_point_search.backend.domains.timeVoteRoom.domain.MeetingDate; import middle_point_search.backend.domains.timeVoteRoom.domain.TimeVote; import middle_point_search.backend.domains.timeVoteRoom.domain.TimeVoteRoom; import middle_point_search.backend.domains.timeVoteRoom.repository.MeetingDateRepository; import middle_point_search.backend.domains.timeVoteRoom.repository.TimeVoteRepository; import middle_point_search.backend.domains.timeVoteRoom.repository.TimeVoteRoomRepository; -import middle_point_search.backend.domains.member.domain.Member; -import middle_point_search.backend.domains.room.domain.Room; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.*; - -import static middle_point_search.backend.common.exception.errorCode.UserErrorCode.*; -import static middle_point_search.backend.domains.timeVoteRoom.dto.TimeVoteRoomDTO.*; @Service @RequiredArgsConstructor @@ -107,11 +113,19 @@ private List createNewTimeVotes(List dateTimeRanges, TimeVo LocalDateTime memberAvailableStartTime = timeRange.getMemberAvailableStartTime(); LocalDateTime memberAvailableEndTime = timeRange.getMemberAvailableEndTime(); LocalDateTime startDateTime = memberAvailableStartTime.toLocalDate().atStartOfDay(); - Optional meetingDateOpt = meetingDateRepository.findByTimeVoteRoomAndDate(timeVoteRoom, - startDateTime.toLocalDate()); - MeetingDate meetingDate = meetingDateOpt.orElseThrow(() -> new CustomException(VOTE_ROOM_NOT_FOUND)); - TimeVote timeVote = new TimeVote(timeVoteRoom, meetingDate, member, memberAvailableStartTime, + + MeetingDate meetingDate = meetingDateRepository.findByTimeVoteRoomAndDate( + timeVoteRoom, + startDateTime.toLocalDate()) + .orElseThrow(() -> new CustomException(CANDIDATE_NOT_FOUND)); + + TimeVote timeVote = new TimeVote( + timeVoteRoom, + meetingDate, + member, + memberAvailableStartTime, memberAvailableEndTime); + timeVotes.add(timeVote); } return timeVotes; @@ -131,7 +145,8 @@ public TimeVoteRoomResultResponse getTimeVoteResult(Room room) { List details = new ArrayList<>(); // 해당 날짜의 모든 투표 정보 가져오기 - List timeVotes = timeVoteRepository.findAllByTimeVoteRoomAndMeetingDate(timeVoteRoom, meetingDate); + List timeVotes = timeVoteRepository.findAllByTimeVoteRoomAndMeetingDate(timeVoteRoom, + meetingDate); for (TimeVote vote : timeVotes) { List dateTimeList = Arrays.asList( new TimeRange(