diff --git a/src/main/kotlin/roomescape/schedule/business/ScheduleService.kt b/src/main/kotlin/roomescape/schedule/business/ScheduleService.kt index 34b0637a..e080dae5 100644 --- a/src/main/kotlin/roomescape/schedule/business/ScheduleService.kt +++ b/src/main/kotlin/roomescape/schedule/business/ScheduleService.kt @@ -69,6 +69,16 @@ class ScheduleService( throw ScheduleException(ScheduleErrorCode.SCHEDULE_NOT_AVAILABLE) } + @Transactional(readOnly = true) + fun findScheduleOverviewById(id: Long): ScheduleOverviewResponse { + val overview: ScheduleOverview = scheduleRepository.findOverviewByIdOrNull(id) ?: run { + log.warn { "[ScheduleService.findScheduleOverview] 일정 개요 조회 실패: id=$id" } + throw ScheduleException(ScheduleErrorCode.SCHEDULE_NOT_FOUND) + } + + return overview.toOverviewResponse() + } + // ======================================== // All-Admin (본사, 매장 모두 사용가능) // ======================================== diff --git a/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt index 59665b08..c7503bf7 100644 --- a/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt +++ b/src/main/kotlin/roomescape/schedule/infrastructure/persistence/ScheduleRepository.kt @@ -53,4 +53,29 @@ interface ScheduleRepository : JpaRepository { date: LocalDate, themeId: Long? = null ): List + + @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 + ScheduleEntity s + JOIN + ThemeEntity t ON t._id = s.themeId + JOIN + StoreEntity st ON st._id = s.storeId + WHERE + s._id = :id + """) + fun findOverviewByIdOrNull(id: Long): ScheduleOverview? } diff --git a/src/main/kotlin/roomescape/schedule/web/ScheduleDto.kt b/src/main/kotlin/roomescape/schedule/web/ScheduleDto.kt index ddf8633c..10f4f03e 100644 --- a/src/main/kotlin/roomescape/schedule/web/ScheduleDto.kt +++ b/src/main/kotlin/roomescape/schedule/web/ScheduleDto.kt @@ -54,3 +54,25 @@ fun ScheduleEntity.toSummaryResponse() = ScheduleSummaryResponse( themeId = this.themeId, status = this.status ) + +data class ScheduleOverviewResponse( + val id: Long, + val storeId: Long, + val storeName: String, + val date: LocalDate, + val startFrom: LocalTime, + val endAt: LocalTime, + val themeId: Long, + val themeName: String, +) + +fun ScheduleOverview.toOverviewResponse() = ScheduleOverviewResponse( + id = this.id, + storeId = this.storeId, + storeName = this.storeName, + date = this.date, + startFrom = this.time, + endAt = this.getEndAt(), + themeId = this.themeId, + themeName = this.themeName, +)