Skip to content

Commit

Permalink
Merge pull request #134 from IT-Cotato/feature/133-fix-time-vote-error
Browse files Browse the repository at this point in the history
Refactor: 시간투표 에러 해결 (#133)
  • Loading branch information
yooooonshine authored Aug 16, 2024
2 parents 04f73de + c012ea2 commit 3a0c1b9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, "이미 투표방이 존재합니다."),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ public ResponseEntity<DataResponse<PlaceVoteInfoResponse>> placeVoteRoomResultGe
responseCode = "200",
description = "성공"
),
@ApiResponse(
responseCode = "400",
description = "투표 후보가 아닙니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "401",
description = "인증에 실패하였습니다.",
Expand All @@ -245,11 +250,6 @@ public ResponseEntity<DataResponse<PlaceVoteInfoResponse>> placeVoteRoomResultGe
description = "생성된 투표방이 없습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "404",
description = "투표 후보가 아닙니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "409",
description = "이미 투표를 하였습니다.",
Expand Down Expand Up @@ -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 = "인증에 실패하였습니다.",
Expand All @@ -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 = "투표를 한 적이 없습니다.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public ResponseEntity<DataResponse<TimeVoteRoomCreateResponse>> timeVoteRoomRecr
responseCode = "200",
description = "성공"
),
@ApiResponse(
responseCode = "400",
description = "투표 후보가 아닙니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "401",
description = "인증에 실패하였습니다.",
Expand All @@ -190,7 +195,6 @@ public ResponseEntity<DataResponse<TimeVoteRoomCreateResponse>> timeVoteRoomRecr
description = "생성된 투표방이 없습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),

@ApiResponse(
responseCode = "409",
description = "이미 투표를 하였습니다.",
Expand Down Expand Up @@ -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 = "인증에 실패하였습니다.",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -107,11 +113,19 @@ private List<TimeVote> createNewTimeVotes(List<TimeRange> dateTimeRanges, TimeVo
LocalDateTime memberAvailableStartTime = timeRange.getMemberAvailableStartTime();
LocalDateTime memberAvailableEndTime = timeRange.getMemberAvailableEndTime();
LocalDateTime startDateTime = memberAvailableStartTime.toLocalDate().atStartOfDay();
Optional<MeetingDate> 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;
Expand All @@ -131,7 +145,8 @@ public TimeVoteRoomResultResponse getTimeVoteResult(Room room) {
List<TimeVoteDetail> details = new ArrayList<>();

// 해당 날짜의 모든 투표 정보 가져오기
List<TimeVote> timeVotes = timeVoteRepository.findAllByTimeVoteRoomAndMeetingDate(timeVoteRoom, meetingDate);
List<TimeVote> timeVotes = timeVoteRepository.findAllByTimeVoteRoomAndMeetingDate(timeVoteRoom,
meetingDate);
for (TimeVote vote : timeVotes) {
List<TimeRange> dateTimeList = Arrays.asList(
new TimeRange(
Expand Down

0 comments on commit 3a0c1b9

Please sign in to comment.