generated from pricelees/issue-pr-template
60 lines
2.0 KiB
Kotlin
60 lines
2.0 KiB
Kotlin
package roomescape.reservation.business
|
|
|
|
import org.springframework.stereotype.Service
|
|
import org.springframework.transaction.annotation.Transactional
|
|
import roomescape.payment.business.PaymentService
|
|
import roomescape.payment.web.PaymentApproveResponse
|
|
import roomescape.payment.web.PaymentCancelRequest
|
|
import roomescape.payment.web.PaymentCancelResponse
|
|
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
|
import roomescape.reservation.web.ReservationRequest
|
|
import roomescape.reservation.web.ReservationResponse
|
|
import java.time.OffsetDateTime
|
|
|
|
@Service
|
|
@Transactional
|
|
class ReservationWithPaymentService(
|
|
private val reservationService: ReservationService,
|
|
private val paymentService: PaymentService
|
|
) {
|
|
fun addReservationWithPayment(
|
|
request: ReservationRequest,
|
|
paymentInfo: PaymentApproveResponse,
|
|
memberId: Long
|
|
): ReservationResponse {
|
|
val reservation: ReservationEntity = reservationService.addReservation(request, memberId)
|
|
|
|
return paymentService.createPayment(paymentInfo, reservation)
|
|
.reservation
|
|
}
|
|
|
|
fun saveCanceledPayment(
|
|
cancelInfo: PaymentCancelResponse,
|
|
approvedAt: OffsetDateTime,
|
|
paymentKey: String
|
|
) {
|
|
paymentService.createCanceledPayment(cancelInfo, approvedAt, paymentKey)
|
|
}
|
|
|
|
fun removeReservationWithPayment(
|
|
reservationId: Long,
|
|
memberId: Long
|
|
): PaymentCancelRequest {
|
|
val paymentCancelRequest = paymentService.createCanceledPaymentByReservationId(reservationId)
|
|
reservationService.removeReservationById(reservationId, memberId)
|
|
|
|
return paymentCancelRequest
|
|
}
|
|
|
|
@Transactional(readOnly = true)
|
|
fun isNotPaidReservation(reservationId: Long): Boolean = !paymentService.isReservationPaid(reservationId)
|
|
|
|
|
|
fun updateCanceledTime(
|
|
paymentKey: String,
|
|
canceledAt: OffsetDateTime
|
|
) {
|
|
paymentService.updateCanceledTime(paymentKey, canceledAt)
|
|
}
|
|
}
|