diff --git a/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt index 98c3d960..1227edff 100644 --- a/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt +++ b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt @@ -2,23 +2,40 @@ package roomescape.schedule.infrastructure.persistence import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.Query +import roomescape.schedule.business.domain.ScheduleWithThemeSummary import java.time.LocalDate import java.time.LocalTime interface ScheduleRepository : JpaRepository { - fun findAllByDate(date: LocalDate): List - - fun findAllByDateAndThemeId(date: LocalDate, themeId: Long): List - fun existsByDateAndThemeIdAndTime(date: LocalDate, themeId: Long, time: LocalTime): Boolean @Query( """ - SELECT DISTINCT s.themeId - FROM ScheduleEntity s - WHERE s.date = :date - """ + SELECT + new roomescape.schedule.business.domain.ScheduleWithThemeSummary( + s._id, + s.date, + s.time, + t._id, + t.name, + t.difficulty, + t.availableMinutes, + s.status + ) + FROM + ScheduleEntity s + JOIN + ThemeEntity t ON t._id = s.themeId + WHERE + s.storeId = :storeId + AND s.date = :date + AND (:themeId IS NULL OR s.themeId = :themeId) + """ ) - fun findAllUniqueThemeIdByDate(date: LocalDate): List + fun findStoreSchedulesWithThemeByDate( + storeId: Long, + date: LocalDate, + themeId: Long? = null + ): List }