From 89ada4b14699046eba4890716e0331625cd710a7 Mon Sep 17 00:00:00 2001 From: pricelees Date: Thu, 18 Sep 2025 15:27:01 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20schedule=EC=97=90=EC=84=9C=EC=9D=98?= =?UTF-8?q?=20=EC=A1=B4=EC=9E=AC=20=EC=A1=B0=EA=B1=B4=20=ED=99=95=EC=9D=B8?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20storeId=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schedule/business/ScheduleValidator.kt | 6 +++--- .../persistence/ScheduleRepository.kt | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) 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( """