feat: schedule의 요약 정보를 제공하는 메서드 추가 & 날짜로 조회할 때 DISTINCT 쿼리 추가

This commit is contained in:
이상진 2025-09-07 21:39:28 +09:00
parent 3243c936c7
commit 0ff7702c83
3 changed files with 33 additions and 4 deletions

View File

@ -30,8 +30,7 @@ class ScheduleService(
fun findThemesByDate(date: LocalDate): AvailableThemeIdListResponse {
log.info { "[ScheduleService.findThemesByDate] 동일한 날짜의 모든 테마 조회: date=$date" }
return scheduleRepository.findAllByDate(date)
.toThemeIdListResponse()
return AvailableThemeIdListResponse(scheduleRepository.findAllUniqueThemeIdByDate(date))
.also {
log.info { "[ScheduleService.findThemesByDate] date=${date}${it.themeIds.size}개 테마 조회 완료" }
}
@ -54,8 +53,8 @@ class ScheduleService(
val schedule: ScheduleEntity = findOrThrow(id)
val createdBy = memberService.findById(schedule.createdBy).name
val updatedBy = memberService.findById(schedule.updatedBy).name
val createdBy = memberService.findSummaryById(schedule.createdBy).name
val updatedBy = memberService.findSummaryById(schedule.updatedBy).name
return schedule.toDetailRetrieveResponse(createdBy, updatedBy)
.also {
@ -63,6 +62,16 @@ class ScheduleService(
}
}
@Transactional(readOnly = true)
fun findSummaryById(id: Long): ScheduleSummaryResponse {
log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 시작 : id=$id" }
return findOrThrow(id).toSummaryResponse()
.also {
log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 완료: id=$id" }
}
}
@Transactional
fun createSchedule(request: ScheduleCreateRequest): ScheduleCreateResponse {
log.info { "[ScheduleService.createSchedule] 일정 생성 시작: date=${request.date}, time=${request.time}, themeId=${request.themeId}" }

View File

@ -1,6 +1,7 @@
package roomescape.schedule.infrastructure.persistence
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import java.time.LocalDate
import java.time.LocalTime
@ -11,4 +12,11 @@ interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
fun findAllByDateAndThemeId(date: LocalDate, themeId: Long): List<ScheduleEntity>
fun existsByDateAndThemeIdAndTime(date: LocalDate, themeId: Long, time: LocalTime): Boolean
@Query("""
SELECT DISTINCT s.themeId
FROM ScheduleEntity s
WHERE s.date = :date
""")
fun findAllUniqueThemeIdByDate(date: LocalDate): List<Long>
}

View File

@ -66,3 +66,15 @@ fun ScheduleEntity.toDetailRetrieveResponse(createdBy: String, updatedBy: String
updatedAt = this.updatedAt,
updatedBy = updatedBy
)
data class ScheduleSummaryResponse(
val date: LocalDate,
val time: LocalTime,
val themeId: Long
)
fun ScheduleEntity.toSummaryResponse() = ScheduleSummaryResponse(
date = this.date,
time = this.time,
themeId = this.themeId
)