[#52] 만료 예약 / 일정 스케쥴링 작업 추가 및 동시성 처리를 위한 일부 코드 수정 #53

Merged
pricelees merged 18 commits from refactor/#52 into main 2025-10-04 08:40:37 +00:00
3 changed files with 22 additions and 3 deletions
Showing only changes of commit dbc6847877 - Show all commits

View File

@ -154,7 +154,7 @@ class ReservationService(
} }
private fun validateCanCreate(request: PendingReservationCreateRequest) { private fun validateCanCreate(request: PendingReservationCreateRequest) {
val schedule = scheduleService.findSummaryById(request.scheduleId) val schedule = scheduleService.findSummaryWithLock(request.scheduleId)
val theme = themeService.findInfoById(schedule.themeId) val theme = themeService.findInfoById(schedule.themeId)
reservationValidator.validateCanCreate(schedule, theme, request) reservationValidator.validateCanCreate(schedule, theme, request)

View File

@ -174,10 +174,16 @@ class ScheduleService(
// Other-Service (API 없이 다른 서비스에서 호출) // Other-Service (API 없이 다른 서비스에서 호출)
// ======================================== // ========================================
@Transactional(readOnly = true) @Transactional(readOnly = true)
fun findSummaryById(id: Long): ScheduleSummaryResponse { fun findSummaryWithLock(id: Long): ScheduleSummaryResponse {
log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 시작 : id=$id" } 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 { .also {
log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 완료: id=$id" } log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 완료: id=$id" }
} }

View File

@ -1,7 +1,9 @@
package com.sangdol.roomescape.schedule.infrastructure.persistence package com.sangdol.roomescape.schedule.infrastructure.persistence
import com.sangdol.roomescape.schedule.business.domain.ScheduleOverview 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.JpaRepository
import org.springframework.data.jpa.repository.Lock
import org.springframework.data.jpa.repository.Modifying import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param import org.springframework.data.repository.query.Param
@ -11,6 +13,17 @@ import java.time.LocalTime
interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> { 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( @Query(
""" """
SELECT SELECT