Skip to content

Commit

Permalink
fix lckSchedule get api
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong0329 committed Aug 17, 2024
1 parent 161e2ac commit 14d1df7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wable.www.WableServer.api.lck.dto.reponse;

import java.util.List;

public record LckScheduleByDateDto(
String date,
List<LckScheduleGetDto> games
) {
public static LckScheduleByDateDto of(String date, List<LckScheduleGetDto> games) {
return new LckScheduleByDateDto(
date,
games
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.wable.www.WableServer.api.lck.domain.LckSchedule;
import com.wable.www.WableServer.api.lck.dto.reponse.LckRankingGetDto;
import com.wable.www.WableServer.api.lck.dto.reponse.LckScheduleByDateDto;
import com.wable.www.WableServer.api.lck.dto.reponse.LckScheduleGetDto;
import com.wable.www.WableServer.api.lck.repository.LckScheduleRepository;
import com.wable.www.WableServer.common.util.TimeUtilCustom;
Expand All @@ -11,8 +12,10 @@

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
Expand All @@ -21,14 +24,22 @@
public class LckScheduleQueryService {
private final LckScheduleRepository lckScheduleRepository;

public List<LckScheduleGetDto> getLckSchedule() {
public List<LckScheduleByDateDto> getLckSchedule() {
LocalDateTime now = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime endDate = now.with(TemporalAdjusters.next(DayOfWeek.SUNDAY)).plusDays(7);

List<LckSchedule> lckSchedules = lckScheduleRepository.findAllByLckDateBetween(now, endDate);

return lckSchedules.stream()
Map<String, List<LckScheduleGetDto>> groupedByDate = lckSchedules.stream()
.map(lckSchedule -> LckScheduleGetDto.of(lckSchedule, TimeUtilCustom.refineTimeLckSchedule(lckSchedule.getLckDate())))
.collect(Collectors.groupingBy(dto -> {
LocalDateTime gameDateTime = LocalDateTime.parse(dto.gameDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
return TimeUtilCustom.refineDateOnly(gameDateTime);
}));

// 날짜별로 그룹화된 데이터를 LckScheduleByDateDto로 변환
return groupedByDate.entrySet().stream()
.map(entry -> LckScheduleByDateDto.of(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public static String refineTimeLckSchedule(LocalDateTime localDateTime) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return localDateTime.format(formatter);
}

public static String refineDateOnly(LocalDateTime localDateTime) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return localDateTime.format(formatter);
}
}

0 comments on commit 14d1df7

Please sign in to comment.