generated from pricelees/issue-pr-template
<!-- 제목 양식 --> <!-- [이슈번호] 작업 요약 (예시: [#10] Gitea 템플릿 생성) --> ## 📝 관련 이슈 및 PR **PR과 관련된 이슈 번호** - #35 ## ✨ 작업 내용 <!-- 어떤 작업을 했는지 알려주세요! --> - 운영을 고려하여 조금 더 디테일한 정보가 담기도록 결제 스키마 개선(결제수단, 금액, 카드 사용시 카드번호, 할부 정보 등) - 회원의 예약 조회 페이지 개선 및 회원의 예약 취소 기능 도입 ## 🧪 테스트 <!-- 어떤 테스트를 생각했고 진행했는지 알려주세요! --> - 현재 테스트가 과연 신뢰성이 있는가 의문. 추후 전체적인 작업 후 전체 테스트를 재조정할 예정 ## 📚 참고 자료 및 기타 <!-- 참고한 자료, 또는 논의할 사항이 있다면 알려주세요! --> Reviewed-on: #36 Co-authored-by: pricelees <priceelees@gmail.com> Co-committed-by: pricelees <priceelees@gmail.com>
32 lines
1.2 KiB
Kotlin
32 lines
1.2 KiB
Kotlin
package roomescape.common.util
|
|
|
|
import io.github.oshai.kotlinlogging.KLogger
|
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
|
import org.springframework.stereotype.Component
|
|
import org.springframework.transaction.PlatformTransactionManager
|
|
import org.springframework.transaction.TransactionDefinition
|
|
import org.springframework.transaction.support.TransactionTemplate
|
|
import roomescape.common.exception.CommonErrorCode
|
|
import roomescape.common.exception.RoomescapeException
|
|
|
|
private val log: KLogger = KotlinLogging.logger {}
|
|
|
|
@Component
|
|
class TransactionExecutionUtil(
|
|
private val transactionManager: PlatformTransactionManager
|
|
) {
|
|
|
|
fun <T> withNewTransaction(isReadOnly: Boolean, action: () -> T): T {
|
|
val transactionTemplate = TransactionTemplate(transactionManager).apply {
|
|
this.isReadOnly = isReadOnly
|
|
this.propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRES_NEW
|
|
}
|
|
|
|
return transactionTemplate.execute { action() }
|
|
?: run {
|
|
log.error { "[TransactionExecutionUtil.withNewTransaction] 트랜잭션 작업 중 예상치 못한 null 반환 " }
|
|
throw RoomescapeException(CommonErrorCode.UNEXPECTED_SERVER_ERROR)
|
|
}
|
|
}
|
|
}
|