Skip to content

Commit

Permalink
Merge pull request #479 from Kernel360/fix-batch
Browse files Browse the repository at this point in the history
fix: 경기 상태 변경 배치 수정
  • Loading branch information
I-migi authored Nov 27, 2024
2 parents f2e943c + dbce7bc commit 4f150ad
Showing 1 changed file with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,55 @@ public class LeagueStatusProcessor implements ItemProcessor<League, League> {
private final SinglesMatchReader singlesMatchReader;
private final DoublesMatchReader doublesMatchReader;

@Override
public League process(League item) {
LocalDateTime now = LocalDateTime.now();

switch (item.getLeagueStatus()) {
case RECRUITING:
handleRecruiting(item);
break;
case RECRUITING_COMPLETED:
handleRecruitingCompleted(item, now);
break;
case PLAYING:
handlePlaying(item, now);
break;
}

return item;
}

private void handleRecruiting(League item) {
if (!isParticipantCountValid(item)) {
item.cancelLeague();
return item;
} else {
item.completeLeagueRecruiting();
}
}

item.completeLeagueRecruiting();

private void handleRecruitingCompleted(League item, LocalDateTime now) {
if (isLeagueInProgress(item, now)) {
item.startLeague();
}
}

private void handlePlaying(League item, LocalDateTime now) {
if (isLeagueOverdue(item, now)) {
if (!areAllMatchesFinished(item)) {
item.cancelLeague();
return item;
} else {
item.finishLeague();
}
item.finishLeague();
}

return item;
}

private boolean isParticipantCountValid(League item) {
return leagueParticipantReader.countParticipantMember(item.getLeagueId()) == item.getPlayerLimitCount();
}

private boolean isLeagueInProgress(League item, LocalDateTime now) {
return item.getLeagueAt().isBefore(now) && item.getLeagueAt().plusHours(12).isAfter(now);
return item.getLeagueAt().isBefore(now);
}

private boolean isLeagueOverdue(League item, LocalDateTime now) {
Expand All @@ -61,3 +79,4 @@ private boolean areAllMatchesFinished(League item) {
&& doublesMatchReader.allMatchesFinishedForLeague(item.getLeagueId());
}
}

0 comments on commit 4f150ad

Please sign in to comment.