generated from pricelees/issue-pr-template
[#18] 코드 정리 및 일부 컨벤션 통일 #19
@ -5,11 +5,15 @@ import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import roomescape.common.exception.ErrorType
|
||||
import roomescape.common.exception.RoomescapeException
|
||||
import roomescape.payment.infrastructure.client.PaymentApproveResponse
|
||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentEntity
|
||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentRepository
|
||||
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||
import roomescape.payment.infrastructure.persistence.PaymentRepository
|
||||
import roomescape.payment.web.*
|
||||
import roomescape.payment.web.PaymentCancelRequest
|
||||
import roomescape.payment.web.PaymentCancelResponse
|
||||
import roomescape.payment.web.PaymentCreateResponse
|
||||
import roomescape.payment.web.toCreateResponse
|
||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||
import java.time.OffsetDateTime
|
||||
|
||||
@ -22,15 +26,15 @@ class PaymentService(
|
||||
fun createPayment(
|
||||
paymentResponse: PaymentApproveResponse,
|
||||
reservation: ReservationEntity
|
||||
): ReservationPaymentResponse = PaymentEntity(
|
||||
): PaymentCreateResponse = PaymentEntity(
|
||||
orderId = paymentResponse.orderId,
|
||||
paymentKey = paymentResponse.paymentKey,
|
||||
totalAmount = paymentResponse.totalAmount,
|
||||
totalAmount = paymentResponse.amount,
|
||||
reservation = reservation,
|
||||
approvedAt = paymentResponse.approvedAt
|
||||
).also {
|
||||
paymentRepository.save(it)
|
||||
}.toReservationPaymentResponse()
|
||||
}.toCreateResponse()
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
fun isReservationPaid(
|
||||
|
||||
@ -12,8 +12,6 @@ import org.springframework.stereotype.Component
|
||||
import org.springframework.web.client.RestClient
|
||||
import roomescape.common.exception.ErrorType
|
||||
import roomescape.common.exception.RoomescapeException
|
||||
import roomescape.payment.web.PaymentApproveRequest
|
||||
import roomescape.payment.web.PaymentApproveResponse
|
||||
import roomescape.payment.web.PaymentCancelRequest
|
||||
import roomescape.payment.web.PaymentCancelResponse
|
||||
import java.io.IOException
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
package roomescape.payment.infrastructure.client
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import java.time.OffsetDateTime
|
||||
|
||||
data class TossPaymentErrorResponse(
|
||||
val code: String,
|
||||
val message: String
|
||||
)
|
||||
|
||||
data class PaymentApproveRequest(
|
||||
val paymentKey: String,
|
||||
val orderId: String,
|
||||
val amount: Long,
|
||||
val paymentType: String
|
||||
)
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
data class PaymentApproveResponse(
|
||||
val paymentKey: String,
|
||||
val orderId: String,
|
||||
val totalAmount: Long,
|
||||
val approvedAt: OffsetDateTime
|
||||
)
|
||||
@ -1,6 +0,0 @@
|
||||
package roomescape.payment.infrastructure.client
|
||||
|
||||
data class TossPaymentErrorResponse(
|
||||
val code: String,
|
||||
val message: String
|
||||
)
|
||||
@ -1,6 +1,5 @@
|
||||
package roomescape.payment.web
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||
import roomescape.payment.infrastructure.client.PaymentCancelResponseDeserializer
|
||||
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||
@ -8,21 +7,6 @@ import roomescape.reservation.web.ReservationResponse
|
||||
import roomescape.reservation.web.toCreateResponse
|
||||
import java.time.OffsetDateTime
|
||||
|
||||
data class PaymentApproveRequest(
|
||||
val paymentKey: String,
|
||||
val orderId: String,
|
||||
val amount: Long,
|
||||
val paymentType: String
|
||||
)
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
data class PaymentApproveResponse(
|
||||
val paymentKey: String,
|
||||
val orderId: String,
|
||||
val approvedAt: OffsetDateTime,
|
||||
val totalAmount: Long
|
||||
)
|
||||
|
||||
data class PaymentCancelRequest(
|
||||
val paymentKey: String,
|
||||
val amount: Long,
|
||||
@ -37,7 +21,7 @@ data class PaymentCancelResponse(
|
||||
val canceledAt: OffsetDateTime
|
||||
)
|
||||
|
||||
data class ReservationPaymentResponse(
|
||||
data class PaymentCreateResponse(
|
||||
val id: Long,
|
||||
val orderId: String,
|
||||
val paymentKey: String,
|
||||
@ -46,7 +30,7 @@ data class ReservationPaymentResponse(
|
||||
val approvedAt: OffsetDateTime
|
||||
)
|
||||
|
||||
fun PaymentEntity.toReservationPaymentResponse(): ReservationPaymentResponse = ReservationPaymentResponse(
|
||||
fun PaymentEntity.toCreateResponse(): PaymentCreateResponse = PaymentCreateResponse(
|
||||
id = this.id!!,
|
||||
orderId = this.orderId,
|
||||
paymentKey = this.paymentKey,
|
||||
|
||||
@ -3,7 +3,7 @@ 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.infrastructure.client.PaymentApproveResponse
|
||||
import roomescape.payment.web.PaymentCancelRequest
|
||||
import roomescape.payment.web.PaymentCancelResponse
|
||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||
|
||||
@ -7,9 +7,9 @@ import org.springframework.web.bind.annotation.*
|
||||
import roomescape.auth.web.support.MemberId
|
||||
import roomescape.common.dto.response.CommonApiResponse
|
||||
import roomescape.common.exception.RoomescapeException
|
||||
import roomescape.payment.infrastructure.client.PaymentApproveRequest
|
||||
import roomescape.payment.infrastructure.client.TossPaymentClient
|
||||
import roomescape.payment.web.PaymentApproveRequest
|
||||
import roomescape.payment.web.PaymentApproveResponse
|
||||
import roomescape.payment.infrastructure.client.PaymentApproveResponse
|
||||
import roomescape.payment.web.PaymentCancelRequest
|
||||
import roomescape.reservation.business.ReservationService
|
||||
import roomescape.reservation.business.ReservationWithPaymentService
|
||||
|
||||
@ -2,7 +2,7 @@ package roomescape.reservation.web
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
import roomescape.payment.web.PaymentApproveRequest
|
||||
import roomescape.payment.infrastructure.client.PaymentApproveRequest
|
||||
import java.time.LocalDate
|
||||
|
||||
@Schema(name = "관리자 예약 저장 요청", description = "관리자의 예약 저장 요청시 사용됩니다.")
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package roomescape.payment.infrastructure.client
|
||||
|
||||
import roomescape.payment.web.PaymentApproveRequest
|
||||
import roomescape.payment.infrastructure.client.PaymentApproveRequest
|
||||
import roomescape.payment.web.PaymentCancelRequest
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
|
||||
@ -16,7 +16,6 @@ import org.springframework.test.web.client.response.MockRestResponseCreators.wit
|
||||
import org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess
|
||||
import roomescape.common.exception.ErrorType
|
||||
import roomescape.common.exception.RoomescapeException
|
||||
import roomescape.payment.web.PaymentApproveResponse
|
||||
import roomescape.payment.web.PaymentCancelRequest
|
||||
import roomescape.payment.web.PaymentCancelResponse
|
||||
|
||||
@ -53,7 +52,7 @@ class TossPaymentClientTest(
|
||||
assertSoftly(paymentResponse) {
|
||||
this.paymentKey shouldBe paymentRequest.paymentKey
|
||||
this.orderId shouldBe paymentRequest.orderId
|
||||
this.totalAmount shouldBe paymentRequest.amount
|
||||
this.amount shouldBe paymentRequest.amount
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import io.mockk.mockk
|
||||
import roomescape.payment.business.PaymentService
|
||||
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||
import roomescape.payment.web.PaymentCancelRequest
|
||||
import roomescape.payment.web.toReservationPaymentResponse
|
||||
import roomescape.payment.web.toCreateResponse
|
||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||
import roomescape.reservation.infrastructure.persistence.ReservationStatus
|
||||
import roomescape.reservation.web.ReservationRequest
|
||||
@ -53,7 +53,7 @@ class ReservationWithPaymentServiceTest : FunSpec({
|
||||
|
||||
every {
|
||||
paymentService.createPayment(paymentApproveResponse, reservationEntity)
|
||||
} returns paymentEntity.toReservationPaymentResponse()
|
||||
} returns paymentEntity.toCreateResponse()
|
||||
|
||||
val result: ReservationResponse = reservationWithPaymentService.addReservationWithPayment(
|
||||
request = reservationRequest,
|
||||
|
||||
@ -66,7 +66,7 @@ class ReservationControllerTest(
|
||||
val paymentApproveResponse = PaymentFixture.createApproveResponse().copy(
|
||||
paymentKey = reservationRequest.paymentKey,
|
||||
orderId = reservationRequest.orderId,
|
||||
totalAmount = reservationRequest.amount,
|
||||
amount = reservationRequest.amount,
|
||||
)
|
||||
|
||||
every {
|
||||
@ -116,7 +116,7 @@ class ReservationControllerTest(
|
||||
val paymentApproveResponse = PaymentFixture.createApproveResponse().copy(
|
||||
paymentKey = reservationRequest.paymentKey,
|
||||
orderId = reservationRequest.orderId,
|
||||
totalAmount = reservationRequest.amount,
|
||||
amount = reservationRequest.amount,
|
||||
)
|
||||
|
||||
every {
|
||||
|
||||
@ -6,8 +6,8 @@ import roomescape.member.infrastructure.persistence.MemberEntity
|
||||
import roomescape.member.infrastructure.persistence.Role
|
||||
import roomescape.payment.infrastructure.persistence.CanceledPaymentEntity
|
||||
import roomescape.payment.infrastructure.persistence.PaymentEntity
|
||||
import roomescape.payment.web.PaymentApproveRequest
|
||||
import roomescape.payment.web.PaymentApproveResponse
|
||||
import roomescape.payment.infrastructure.client.PaymentApproveRequest
|
||||
import roomescape.payment.infrastructure.client.PaymentApproveResponse
|
||||
import roomescape.payment.web.PaymentCancelRequest
|
||||
import roomescape.payment.web.PaymentCancelResponse
|
||||
import roomescape.reservation.infrastructure.persistence.ReservationEntity
|
||||
@ -168,7 +168,7 @@ object PaymentFixture {
|
||||
paymentKey = PAYMENT_KEY,
|
||||
orderId = ORDER_ID,
|
||||
approvedAt = OffsetDateTime.now(),
|
||||
totalAmount = AMOUNT
|
||||
amount = AMOUNT
|
||||
)
|
||||
|
||||
fun createCancelRequest(): PaymentCancelRequest = PaymentCancelRequest(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user