Skip to content

Commit

Permalink
Merge pull request #124 from onetime-with-members/fix/#123/most-error
Browse files Browse the repository at this point in the history
[fix] : 가장 많이 되는 시간 조회 시, 6번째 항목에서 시간이 끊기는 문제를 해결한다
  • Loading branch information
bbbang105 authored Dec 1, 2024
2 parents d8c0382 + dbf89da commit 332553a
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 332553a

Please sign in to comment.