refactor: 일정 조회 쿼리 일부 수정

This commit is contained in:
이상진 2025-09-27 15:26:57 +09:00
parent 23ea8d13ea
commit 6dc128202a
2 changed files with 30 additions and 28 deletions

View File

@ -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())

View File

@ -8,7 +8,8 @@ import java.time.LocalTime
interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
@Query("""
@Query(
"""
SELECT
COUNT(s) > 0
FROM
@ -18,35 +19,34 @@ interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
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<ScheduleEntity, Long> {
themeId: Long? = null
): List<ScheduleOverview>
@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<ScheduleEntity, Long> {
StoreEntity st ON st._id = s.storeId
WHERE
s._id = :id
""")
"""
)
fun findOverviewByIdOrNull(id: Long): ScheduleOverview?
}