Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] : 가장 많이 되는 시간 조회 시, 6번째 항목에서 시간이 끊기는 문제를 해결한다 #124

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}