Skip to content

Commit

Permalink
#123 [fix] : 가장 많이 되는 시간 조회 문제를 해결한다
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Dec 1, 2024
1 parent d8c0382 commit dbf89da
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/side/onetime/service/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,22 @@ private List<GetMostPossibleTime> buildMostPossibleTimes(Map<Schedule, List<Stri
List<GetMostPossibleTime> mostPossibleTimes = new ArrayList<>();
GetMostPossibleTime previousTime = null;

boolean stopFlag = false;
for (Map.Entry<Schedule, List<String>> entry : scheduleToNamesMap.entrySet()) {
Schedule schedule = entry.getKey();
List<String> curNames = entry.getValue();

if (curNames.size() == mostPossibleCnt) {
// 이전 시간대와 병합 가능한 경우
if (canMergeWithPrevious(previousTime, schedule, curNames, category)) {
// 종료 시간을 더해 업데이트
// 이전 시간대와 병합 가능한 경우
previousTime = previousTime.updateEndTime(schedule.getTime());
mostPossibleTimes.set(mostPossibleTimes.size() - 1, previousTime);
mostPossibleTimes.set(mostPossibleTimes.size() - 1, previousTime); // 종료 시간을 더해 업데이트
} else {
// 새로운 시간대를 추가하는 경우
if (mostPossibleTimes.size() == MAX_MOST_POSSIBLE_TIMES_SIZE) {
// 6개를 찾았을 시 종료
stopFlag = true;
}
List<String> impossibleNames = allMembersName.stream()
.filter(name -> !curNames.contains(name))
.toList();
Expand All @@ -250,8 +255,7 @@ private List<GetMostPossibleTime> buildMostPossibleTimes(Map<Schedule, List<Stri
previousTime = newTime;
}
}

if (mostPossibleTimes.size() == MAX_MOST_POSSIBLE_TIMES_SIZE) {
if (stopFlag) {
break;
}
}
Expand Down Expand Up @@ -333,4 +337,4 @@ private EventParticipation verifyUserIsEventCreator(String authorizationHeader,

return eventParticipation;
}
}
}

0 comments on commit dbf89da

Please sign in to comment.