generated from pricelees/issue-pr-template
76 lines
3.1 KiB
Kotlin
76 lines
3.1 KiB
Kotlin
package roomescape.reservation.business
|
|
|
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
|
import org.springframework.stereotype.Service
|
|
import org.springframework.transaction.annotation.Transactional
|
|
import roomescape.payment.business.PaymentService
|
|
import roomescape.payment.infrastructure.client.PaymentApproveResponse
|
|
import roomescape.payment.web.PaymentCancelRequest
|
|
import roomescape.payment.web.PaymentCancelResponse
|
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
|
import roomescape.reservation.web.ReservationCreateResponse
|
|
import roomescape.reservation.web.ReservationCreateWithPaymentRequest
|
|
import roomescape.reservation.web.toCreateResponse
|
|
import java.time.OffsetDateTime
|
|
|
|
private val log = KotlinLogging.logger {}
|
|
|
|
@Service
|
|
@Transactional
|
|
class ReservationWithPaymentService(
|
|
private val reservationWriteService: ReservationWriteService,
|
|
private val paymentService: PaymentService,
|
|
) {
|
|
fun createReservationAndPayment(
|
|
request: ReservationCreateWithPaymentRequest,
|
|
approvedPaymentInfo: PaymentApproveResponse,
|
|
memberId: Long,
|
|
): ReservationCreateResponse {
|
|
log.info { "[ReservationWithPaymentService.createReservationAndPayment] 시작: memberId=$memberId, paymentInfo=$approvedPaymentInfo" }
|
|
|
|
val reservation: ReservationEntity = reservationWriteService.createReservationWithPayment(request, memberId)
|
|
.also { paymentService.createPayment(approvedPaymentInfo, it) }
|
|
|
|
return reservation.toCreateResponse()
|
|
.also { log.info { "[ReservationWithPaymentService.createReservationAndPayment] 완료: reservationId=${reservation.id}, paymentId=${it.id}" } }
|
|
}
|
|
|
|
fun createCanceledPayment(
|
|
canceledPaymentInfo: PaymentCancelResponse,
|
|
approvedAt: OffsetDateTime,
|
|
paymentKey: String,
|
|
) {
|
|
paymentService.createCanceledPayment(canceledPaymentInfo, approvedAt, paymentKey)
|
|
}
|
|
|
|
fun deleteReservationAndPayment(
|
|
reservationId: Long,
|
|
memberId: Long,
|
|
): PaymentCancelRequest {
|
|
log.info { "[ReservationWithPaymentService.deleteReservationAndPayment] 시작: reservationId=$reservationId" }
|
|
val paymentCancelRequest = paymentService.createCanceledPayment(reservationId)
|
|
|
|
reservationWriteService.deleteReservation(reservationId, memberId)
|
|
log.info { "[ReservationWithPaymentService.deleteReservationAndPayment] 완료: reservationId=$reservationId" }
|
|
return paymentCancelRequest
|
|
}
|
|
|
|
@Transactional(readOnly = true)
|
|
fun isNotPaidReservation(reservationId: Long): Boolean {
|
|
log.info { "[ReservationWithPaymentService.isNotPaidReservation] 시작: reservationId=$reservationId" }
|
|
|
|
val notPaid: Boolean = !paymentService.existsByReservationId(reservationId)
|
|
|
|
return notPaid.also {
|
|
log.info { "[ReservationWithPaymentService.isNotPaidReservation] 완료: reservationId=$reservationId, isPaid=${notPaid}" }
|
|
}
|
|
}
|
|
|
|
fun updateCanceledTime(
|
|
paymentKey: String,
|
|
canceledAt: OffsetDateTime,
|
|
) {
|
|
paymentService.updateCanceledTime(paymentKey, canceledAt)
|
|
}
|
|
}
|