generated from pricelees/issue-pr-template
75 lines
2.7 KiB
Kotlin
75 lines
2.7 KiB
Kotlin
package roomescape.time.business
|
|
|
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
|
import org.springframework.stereotype.Service
|
|
import org.springframework.transaction.annotation.Transactional
|
|
import roomescape.time.implement.TimeFinder
|
|
import roomescape.time.implement.TimeWriter
|
|
import roomescape.time.infrastructure.persistence.TimeEntity
|
|
import roomescape.time.web.*
|
|
import java.time.LocalDate
|
|
import java.time.LocalTime
|
|
|
|
private val log = KotlinLogging.logger {}
|
|
|
|
@Service
|
|
class TimeService(
|
|
private val timeFinder: TimeFinder,
|
|
private val timeWriter: TimeWriter,
|
|
) {
|
|
@Transactional(readOnly = true)
|
|
fun findById(id: Long): TimeEntity {
|
|
log.debug { "[TimeService.findById] 시작: timeId=$id" }
|
|
|
|
return timeFinder.findById(id)
|
|
.also { log.info { "[TimeService.findById] 완료: timeId=$id, startAt=${it.startAt}" } }
|
|
}
|
|
|
|
@Transactional(readOnly = true)
|
|
fun findTimes(): TimeRetrieveListResponse {
|
|
log.debug { "[TimeService.findTimes] 시작" }
|
|
|
|
return timeFinder.findAll()
|
|
.toResponse()
|
|
.also { log.info { "[TimeService.findTimes] 완료. ${it.times.size}개 반환" } }
|
|
}
|
|
|
|
@Transactional(readOnly = true)
|
|
fun findTimesWithAvailability(date: LocalDate, themeId: Long): TimeWithAvailabilityListResponse {
|
|
log.debug { "[TimeService.findTimesWithAvailability] 시작: date=$date, themeId=$themeId" }
|
|
|
|
val times: List<TimeWithAvailabilityResponse> =
|
|
timeFinder.findAllWithAvailabilityByDateAndThemeId(date, themeId)
|
|
.map {
|
|
TimeWithAvailabilityResponse(
|
|
id = it.timeId,
|
|
startAt = it.startAt,
|
|
isAvailable = it.isReservable
|
|
)
|
|
}
|
|
|
|
return TimeWithAvailabilityListResponse(times)
|
|
.also { log.info { "[TimeService.findTimesWithAvailability] ${it.times.size}개 반환: date=$date, themeId=$themeId" } }
|
|
}
|
|
|
|
@Transactional
|
|
fun createTime(request: TimeCreateRequest): TimeCreateResponse {
|
|
val startAt: LocalTime = request.startAt
|
|
log.debug { "[TimeService.createTime] 시작: startAt=${startAt}" }
|
|
|
|
return timeWriter.create(startAt)
|
|
.toCreateResponse()
|
|
.also { log.info { "[TimeService.createTime] 완료: startAt=${startAt}, timeId=${it.id}" } }
|
|
}
|
|
|
|
@Transactional
|
|
fun deleteTime(id: Long) {
|
|
log.debug { "[TimeService.deleteTime] 시작: timeId=$id" }
|
|
|
|
val time: TimeEntity = timeFinder.findById(id)
|
|
|
|
timeWriter.delete(time)
|
|
.also { log.info { "[TimeService.deleteTime] 완료: timeId=$id, startAt=${time.startAt}" } }
|
|
}
|
|
}
|