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 storeName: String,
val date: LocalDate, val date: LocalDate,
val time: LocalTime, val time: LocalTime,
val status: ScheduleStatus,
val themeId: Long, val themeId: Long,
val themeName: String, val themeName: String,
val themeDifficulty: Difficulty, val themeDifficulty: Difficulty,
val themeAvailableMinutes: Short, val themeAvailableMinutes: Short
val status: ScheduleStatus
) { ) {
fun getEndAt(): LocalTime { fun getEndAt(): LocalTime {
return time.plusMinutes(themeAvailableMinutes.toLong()) return time.plusMinutes(themeAvailableMinutes.toLong())

View File

@ -8,7 +8,8 @@ import java.time.LocalTime
interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> { interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
@Query(""" @Query(
"""
SELECT SELECT
COUNT(s) > 0 COUNT(s) > 0
FROM FROM
@ -18,7 +19,8 @@ interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
AND s.date = :date AND s.date = :date
AND s.themeId = :themeId AND s.themeId = :themeId
AND s.time = :time AND s.time = :time
""") """
)
fun existsDuplicate(storeId: Long, date: LocalDate, themeId: Long, time: LocalTime): Boolean fun existsDuplicate(storeId: Long, date: LocalDate, themeId: Long, time: LocalTime): Boolean
@Query( @Query(
@ -30,22 +32,20 @@ interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
st.name, st.name,
s.date, s.date,
s.time, s.time,
s.status,
t._id, t._id,
t.name, t.name,
t.difficulty, t.difficulty,
t.availableMinutes, t.availableMinutes
s.status
) )
FROM FROM
ScheduleEntity s ScheduleEntity s
JOIN JOIN
ThemeEntity t ON t._id = s.themeId ThemeEntity t ON t._id = s.themeId and (:themeId IS NULL OR t._id = :themeId)
JOIN JOIN
StoreEntity st ON st._id = s.storeId StoreEntity st ON st._id = s.storeId and st._id = :storeId
WHERE WHERE
s.storeId = :storeId s.date = :date
AND s.date = :date
AND (:themeId IS NULL OR s.themeId = :themeId)
""" """
) )
fun findStoreSchedulesWithThemeByDate( fun findStoreSchedulesWithThemeByDate(
@ -54,7 +54,8 @@ interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
themeId: Long? = null themeId: Long? = null
): List<ScheduleOverview> ): List<ScheduleOverview>
@Query(""" @Query(
"""
SELECT SELECT
new roomescape.schedule.business.domain.ScheduleOverview( new roomescape.schedule.business.domain.ScheduleOverview(
s._id, s._id,
@ -62,11 +63,11 @@ interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
st.name, st.name,
s.date, s.date,
s.time, s.time,
s.status,
t._id, t._id,
t.name, t.name,
t.difficulty, t.difficulty,
t.availableMinutes, t.availableMinutes
s.status
) )
FROM FROM
ScheduleEntity s ScheduleEntity s
@ -76,6 +77,7 @@ interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
StoreEntity st ON st._id = s.storeId StoreEntity st ON st._id = s.storeId
WHERE WHERE
s._id = :id s._id = :id
""") """
)
fun findOverviewByIdOrNull(id: Long): ScheduleOverview? fun findOverviewByIdOrNull(id: Long): ScheduleOverview?
} }