From 6dc128202a3e1522c4ce941f8f0c85020b778f03 Mon Sep 17 00:00:00 2001 From: pricelees Date: Sat, 27 Sep 2025 15:26:57 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=9D=BC=EC=A0=95=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=20=EC=9D=BC=EB=B6=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/domain/ScheduleOverview.kt | 4 +- .../persistence/ScheduleRepository.kt | 54 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/roomescape/schedule/business/domain/ScheduleOverview.kt b/src/main/kotlin/roomescape/schedule/business/domain/ScheduleOverview.kt index e9d9b523..de099149 100644 --- a/src/main/kotlin/roomescape/schedule/business/domain/ScheduleOverview.kt +++ b/src/main/kotlin/roomescape/schedule/business/domain/ScheduleOverview.kt @@ -11,11 +11,11 @@ class ScheduleOverview( val storeName: String, val date: LocalDate, val time: LocalTime, + val status: ScheduleStatus, val themeId: Long, val themeName: String, val themeDifficulty: Difficulty, - val themeAvailableMinutes: Short, - val status: ScheduleStatus + val themeAvailableMinutes: Short ) { fun getEndAt(): LocalTime { return time.plusMinutes(themeAvailableMinutes.toLong()) diff --git a/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt index c7503bf7..3189b1aa 100644 --- a/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt +++ b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt @@ -8,7 +8,8 @@ import java.time.LocalTime interface ScheduleRepository : JpaRepository { - @Query(""" + @Query( + """ SELECT COUNT(s) > 0 FROM @@ -18,35 +19,34 @@ interface ScheduleRepository : JpaRepository { AND s.date = :date AND s.themeId = :themeId AND s.time = :time - """) + """ + ) fun existsDuplicate(storeId: Long, date: LocalDate, themeId: Long, time: LocalTime): Boolean @Query( """ - SELECT + SELECT new roomescape.schedule.business.domain.ScheduleOverview( s._id, st._id, st.name, s.date, s.time, + s.status, t._id, t.name, t.difficulty, - t.availableMinutes, - s.status + t.availableMinutes ) FROM ScheduleEntity s JOIN - ThemeEntity t ON t._id = s.themeId + ThemeEntity t ON t._id = s.themeId and (:themeId IS NULL OR t._id = :themeId) JOIN - StoreEntity st ON st._id = s.storeId + StoreEntity st ON st._id = s.storeId and st._id = :storeId WHERE - s.storeId = :storeId - AND s.date = :date - AND (:themeId IS NULL OR s.themeId = :themeId) - """ + s.date = :date + """ ) fun findStoreSchedulesWithThemeByDate( storeId: Long, @@ -54,21 +54,22 @@ interface ScheduleRepository : JpaRepository { themeId: Long? = null ): List - @Query(""" - SELECT + @Query( + """ + SELECT new roomescape.schedule.business.domain.ScheduleOverview( - s._id, - st._id, - st.name, - s.date, - s.time, - t._id, - t.name, - t.difficulty, - t.availableMinutes, - s.status - ) - FROM + s._id, + st._id, + st.name, + s.date, + s.time, + s.status, + t._id, + t.name, + t.difficulty, + t.availableMinutes + ) + FROM ScheduleEntity s JOIN ThemeEntity t ON t._id = s.themeId @@ -76,6 +77,7 @@ interface ScheduleRepository : JpaRepository { StoreEntity st ON st._id = s.storeId WHERE s._id = :id - """) + """ + ) fun findOverviewByIdOrNull(id: Long): ScheduleOverview? }