refactor: schedule에서의 존재 조건 확인을 위한 storeId 필드 추가

This commit is contained in:
이상진 2025-09-18 15:27:01 +09:00
parent 54648a6c04
commit 89ada4b146
2 changed files with 15 additions and 4 deletions

View File

@ -41,13 +41,13 @@ class ScheduleValidator(
val time: LocalTime = request.time val time: LocalTime = request.time
val themeId: Long = request.themeId val themeId: Long = request.themeId
validateAlreadyExists(date, themeId, time) validateAlreadyExists(storeId, date, themeId, time)
validateNotInPast(date, time) validateNotInPast(date, time)
validateTimeNotConflict(storeId, request.date, request.themeId, request.time) validateTimeNotConflict(storeId, request.date, request.themeId, request.time)
} }
private fun validateAlreadyExists(date: LocalDate, themeId: Long, time: LocalTime) { private fun validateAlreadyExists(storeId: Long, date: LocalDate, themeId: Long, time: LocalTime) {
if (scheduleRepository.existsByDateAndThemeIdAndTime(date, themeId, time)) { if (scheduleRepository.existsDuplicate(storeId, date, themeId, time)) {
log.info { log.info {
"[ScheduleValidator.validateAlreadyExists] 동일한 날짜, 테마, 시간 존재로 인한 실패: date=${date} / themeId=${themeId} / time=${time}" "[ScheduleValidator.validateAlreadyExists] 동일한 날짜, 테마, 시간 존재로 인한 실패: date=${date} / themeId=${themeId} / time=${time}"
} }

View File

@ -8,7 +8,18 @@ import java.time.LocalTime
interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> { interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
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( @Query(
""" """