generated from pricelees/issue-pr-template
[#52] 만료 예약 / 일정 스케쥴링 작업 추가 및 동시성 처리를 위한 일부 코드 수정 #53
@ -154,7 +154,7 @@ class ReservationService(
|
||||
}
|
||||
|
||||
private fun validateCanCreate(request: PendingReservationCreateRequest) {
|
||||
val schedule = scheduleService.findSummaryById(request.scheduleId)
|
||||
val schedule = scheduleService.findSummaryWithLock(request.scheduleId)
|
||||
val theme = themeService.findInfoById(schedule.themeId)
|
||||
|
||||
reservationValidator.validateCanCreate(schedule, theme, request)
|
||||
|
||||
@ -174,10 +174,16 @@ class ScheduleService(
|
||||
// Other-Service (API 없이 다른 서비스에서 호출)
|
||||
// ========================================
|
||||
@Transactional(readOnly = true)
|
||||
fun findSummaryById(id: Long): ScheduleSummaryResponse {
|
||||
fun findSummaryWithLock(id: Long): ScheduleSummaryResponse {
|
||||
log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 시작 : id=$id" }
|
||||
|
||||
return findOrThrow(id).toSummaryResponse()
|
||||
val schedule: ScheduleEntity = scheduleRepository.findByIdForUpdate(id)
|
||||
?: run {
|
||||
log.warn { "[ScheduleService.updateSchedule] 일정 조회 실패. id=$id" }
|
||||
throw ScheduleException(ScheduleErrorCode.SCHEDULE_NOT_FOUND)
|
||||
}
|
||||
|
||||
return schedule.toSummaryResponse()
|
||||
.also {
|
||||
log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 완료: id=$id" }
|
||||
}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package com.sangdol.roomescape.schedule.infrastructure.persistence
|
||||
|
||||
import com.sangdol.roomescape.schedule.business.domain.ScheduleOverview
|
||||
import jakarta.persistence.LockModeType
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Lock
|
||||
import org.springframework.data.jpa.repository.Modifying
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.data.repository.query.Param
|
||||
@ -11,6 +13,17 @@ import java.time.LocalTime
|
||||
|
||||
interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
|
||||
|
||||
@Lock(value = LockModeType.PESSIMISTIC_WRITE)
|
||||
@Query("""
|
||||
SELECT
|
||||
s
|
||||
FROM
|
||||
ScheduleEntity s
|
||||
WHERE
|
||||
s._id = :id
|
||||
""")
|
||||
fun findByIdForUpdate(id: Long): ScheduleEntity?
|
||||
|
||||
@Query(
|
||||
"""
|
||||
SELECT
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user