Skip to content

Commit

Permalink
Merge pull request #198 from 42organization/fix-match-get-api
Browse files Browse the repository at this point in the history
[fix] get match api error
  • Loading branch information
kmularise authored Aug 8, 2023
2 parents 370719b + 240b5d7 commit d1870e2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,37 @@ public SlotStatusResponseListDto getAllMatchStatus(UserDto userDto, Option optio
List<Game> games = gameRepository.findAllBetween(slotGenerator.getNow(), slotGenerator.getMaxTime());
slotGenerator.addPastSlots();
slotGenerator.addMatchedSlots(games);

Optional<Game> myGame = gameRepository.findByStatusTypeAndUserId(StatusType.BEFORE, userDto.getId());
Set<LocalDateTime> gameTimes = games.stream().map(Game::getStartTime).collect(Collectors.toSet());
if (myGame.isPresent()) {
groupEnrolledSlots(slotGenerator, myGame.get());
groupEnrolledSlots(slotGenerator, myGame.get(), gameTimes);
} else {
groupEnrolledSlots(slotGenerator);
groupEnrolledSlots(slotGenerator, gameTimes);
}
return slotGenerator.getResponseListDto();
}

private void groupEnrolledSlots(SlotGenerator slotGenerator, Game myGame) {
private void groupEnrolledSlots(SlotGenerator slotGenerator, Game myGame, Set<LocalDateTime> gameTimes) {
Set<LocalDateTime> enrolledTimes = redisMatchTimeRepository.getAllEnrolledStartTimes();
slotGenerator.addMySlots(myGame);
Set<LocalDateTime> notMyEnrolledTimes = enrolledTimes.stream().filter(e -> !e.equals(myGame.getStartTime()))
Set<LocalDateTime> notMyEnrolledTimes = enrolledTimes.stream()
.filter(e -> !e.equals(myGame.getStartTime()) && !gameTimes.contains(e))
.collect(Collectors.toSet());
notMyEnrolledTimes.stream().forEach(time -> {
List<RedisMatchUser> allMatchUsers = redisMatchTimeRepository.getAllMatchUsers(time);
slotGenerator.groupEnrolledSlot(time, allMatchUsers);
}
);
}
private void groupEnrolledSlots(SlotGenerator slotGenerator) {
private void groupEnrolledSlots(SlotGenerator slotGenerator, Set<LocalDateTime> gameTimes) {
Set<LocalDateTime> enrolledTimes = redisMatchTimeRepository.getAllEnrolledStartTimes();
Set<RedisMatchTime> allMatchTime = redisMatchUserRepository.getAllMatchTime(slotGenerator.getMatchUser().getUserId());
slotGenerator.addMySlots(allMatchTime);
Set<LocalDateTime> times = allMatchTime.stream().map(RedisMatchTime::getStartTime)
.collect(Collectors.toSet());
Set<LocalDateTime> notMyEnrolledTimes = enrolledTimes.stream().filter(e -> !times.contains(e))
Set<LocalDateTime> notMyEnrolledTimes = enrolledTimes.stream()
.filter(e -> !times.contains(e) && !gameTimes.contains(e))
.collect(Collectors.toSet());
notMyEnrolledTimes.stream().forEach(
time -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,41 @@ void readMyTableBeforeMakingGame() {
}

}

@DisplayName("슬롯 조회 : 게임 등록 되면 제 3자한테 closed 처리")
@Test
void getClosedStatusOfExistGame() {
matchService.makeMatch(UserDto.from(users.get(1)), Option.NORMAL, slotTimes.get(3));
matchService.makeMatch(UserDto.from(users.get(2)), Option.NORMAL, slotTimes.get(3));
SlotStatusResponseListDto allMatchStatus = matchFindService.getAllMatchStatus(UserDto.from(users.get(3)),
Option.NORMAL);
for (List<SlotStatusDto> dtos : allMatchStatus.getMatchBoards()) {
for (SlotStatusDto dto: dtos) {
if (dto.getStartTime().equals(slotTimes.get(3))) {
Assertions.assertThat(dto.getStatus()).isEqualTo(SlotStatus.CLOSE.getCode());
}
}
}
}

@DisplayName("슬롯 조회 : 게임 등록 되면 제3자가 다른 게임 등록해도 제 3자한테 closed 처리")
@Test
void getClosedStatusOfExistGame2() {
matchService.makeMatch(UserDto.from(users.get(1)), Option.NORMAL, slotTimes.get(3));
matchService.makeMatch(UserDto.from(users.get(2)), Option.NORMAL, slotTimes.get(3));
matchService.makeMatch(UserDto.from(users.get(3)), Option.NORMAL, slotTimes.get(4));
matchService.makeMatch(UserDto.from(users.get(4)), Option.NORMAL, slotTimes.get(4));
SlotStatusResponseListDto allMatchStatus = matchFindService.getAllMatchStatus(UserDto.from(users.get(3)),
Option.NORMAL);
for (List<SlotStatusDto> dtos : allMatchStatus.getMatchBoards()) {
for (SlotStatusDto dto: dtos) {
if (dto.getStartTime().equals(slotTimes.get(3))) {
Assertions.assertThat(dto.getStatus()).isEqualTo(SlotStatus.CLOSE.getCode());
}
}
}
}

@DisplayName("current Match 조회 : user가 등록한 슬롯이 매칭되었을 때")
@Test
void readCurrentMatchAfterMakingGameEntity() {
Expand Down

0 comments on commit d1870e2

Please sign in to comment.