diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/lck/dto/reponse/LckScheduleByDateDto.java b/WableServer/src/main/java/com/wable/www/WableServer/api/lck/dto/reponse/LckScheduleByDateDto.java new file mode 100644 index 0000000..0b1c820 --- /dev/null +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/lck/dto/reponse/LckScheduleByDateDto.java @@ -0,0 +1,15 @@ +package com.wable.www.WableServer.api.lck.dto.reponse; + +import java.util.List; + +public record LckScheduleByDateDto( + String date, + List games +) { + public static LckScheduleByDateDto of(String date, List games) { + return new LckScheduleByDateDto( + date, + games + ); + } +} diff --git a/WableServer/src/main/java/com/wable/www/WableServer/api/lck/service/LckScheduleQueryService.java b/WableServer/src/main/java/com/wable/www/WableServer/api/lck/service/LckScheduleQueryService.java index fd18929..b8f6dc6 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/api/lck/service/LckScheduleQueryService.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/api/lck/service/LckScheduleQueryService.java @@ -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; @@ -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 @@ -21,14 +24,22 @@ public class LckScheduleQueryService { private final LckScheduleRepository lckScheduleRepository; - public List getLckSchedule() { + public List getLckSchedule() { LocalDateTime now = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0); LocalDateTime endDate = now.with(TemporalAdjusters.next(DayOfWeek.SUNDAY)).plusDays(7); List lckSchedules = lckScheduleRepository.findAllByLckDateBetween(now, endDate); - return lckSchedules.stream() + Map> 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()); } } diff --git a/WableServer/src/main/java/com/wable/www/WableServer/common/util/TimeUtilCustom.java b/WableServer/src/main/java/com/wable/www/WableServer/common/util/TimeUtilCustom.java index e6250e4..1f29b36 100644 --- a/WableServer/src/main/java/com/wable/www/WableServer/common/util/TimeUtilCustom.java +++ b/WableServer/src/main/java/com/wable/www/WableServer/common/util/TimeUtilCustom.java @@ -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); + } }