diff --git a/src/main/kotlin/roomescape/schedule/business/ScheduleValidator.kt b/src/main/kotlin/roomescape/schedule/business/ScheduleValidator.kt index e81739f4..d04dede1 100644 --- a/src/main/kotlin/roomescape/schedule/business/ScheduleValidator.kt +++ b/src/main/kotlin/roomescape/schedule/business/ScheduleValidator.kt @@ -41,13 +41,13 @@ class ScheduleValidator( val time: LocalTime = request.time val themeId: Long = request.themeId - validateAlreadyExists(date, themeId, time) + validateAlreadyExists(storeId, date, themeId, time) validateNotInPast(date, time) validateTimeNotConflict(storeId, request.date, request.themeId, request.time) } - private fun validateAlreadyExists(date: LocalDate, themeId: Long, time: LocalTime) { - if (scheduleRepository.existsByDateAndThemeIdAndTime(date, themeId, time)) { + private fun validateAlreadyExists(storeId: Long, date: LocalDate, themeId: Long, time: LocalTime) { + if (scheduleRepository.existsDuplicate(storeId, date, themeId, time)) { log.info { "[ScheduleValidator.validateAlreadyExists] 동일한 날짜, 테마, 시간 존재로 인한 실패: date=${date} / themeId=${themeId} / time=${time}" } diff --git a/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt index 1227edff..9fb8049f 100644 --- a/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt +++ b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt @@ -8,7 +8,18 @@ import java.time.LocalTime interface ScheduleRepository : JpaRepository { - fun existsByDateAndThemeIdAndTime(date: LocalDate, themeId: Long, time: LocalTime): Boolean + @Query(""" + SELECT + COUNT(s) > 0 + FROM + ScheduleEntity s + WHERE + s.storeId = :storeId + AND s.date = :date + AND s.themeId = :themeId + AND s.time = :time + """) + fun existsDuplicate(storeId: Long, date: LocalDate, themeId: Long, time: LocalTime): Boolean @Query( """