From fb3be3bcafd9fc8561bd356ac1c7aad8348e6da4 Mon Sep 17 00:00:00 2001 From: pricelees Date: Mon, 18 Aug 2025 15:55:52 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=83=88=EB=A1=9C=EC=9A=B4=20?= =?UTF-8?q?=EA=B2=B0=EC=A0=9C,=20=EA=B2=B0=EC=A0=9C=20=EC=83=81=EC=84=B8,?= =?UTF-8?q?=20=EC=B7=A8=EC=86=8C=EB=90=9C=20=EA=B2=B0=EC=A0=9C=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20Pay?= =?UTF-8?q?mentFinderV2=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../payment/exception/PaymentErrorCode.kt | 11 ++-- .../payment/implement/PaymentFinderV2.kt | 53 +++++++++++++++++++ .../v2/CanceledPaymentRepositoryV2.kt | 4 +- .../persistence/v2/PaymentDetailRepository.kt | 4 +- 4 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/roomescape/payment/implement/PaymentFinderV2.kt diff --git a/src/main/kotlin/roomescape/payment/exception/PaymentErrorCode.kt b/src/main/kotlin/roomescape/payment/exception/PaymentErrorCode.kt index a415af5d..77188954 100644 --- a/src/main/kotlin/roomescape/payment/exception/PaymentErrorCode.kt +++ b/src/main/kotlin/roomescape/payment/exception/PaymentErrorCode.kt @@ -9,11 +9,12 @@ enum class PaymentErrorCode( override val message: String ) : ErrorCode { PAYMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "P001", "결제 정보를 찾을 수 없어요."), - CANCELED_PAYMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "P002", "취소된 결제 정보를 찾을 수 없어요."), - PAYMENT_CLIENT_ERROR(HttpStatus.BAD_REQUEST, "P003", "결제에 실패했어요. 결제 수단을 확인한 후 다시 시도해주세요."), - ORGANIZATION_CODE_NOT_FOUND(HttpStatus.NOT_FOUND, "P004", "은행 / 카드사 정보를 찾을 수 없어요."), - TYPE_NOT_FOUND(HttpStatus.NOT_FOUND, "P005", "타입 정보를 찾을 수 없어요."), - NOT_SUPPORTED_PAYMENT_TYPE(HttpStatus.BAD_REQUEST, "P006", "지원하지 않는 결제 수단이에요."), + PAYMENT_DETAIL_NOT_FOUND(HttpStatus.NOT_FOUND, "P002", "결제 상세 정보를 찾을 수 없어요."), + CANCELED_PAYMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "P003", "취소된 결제 정보를 찾을 수 없어요."), + PAYMENT_CLIENT_ERROR(HttpStatus.BAD_REQUEST, "P004", "결제에 실패했어요. 결제 수단을 확인한 후 다시 시도해주세요."), + ORGANIZATION_CODE_NOT_FOUND(HttpStatus.NOT_FOUND, "P005", "은행 / 카드사 정보를 찾을 수 없어요."), + TYPE_NOT_FOUND(HttpStatus.NOT_FOUND, "P006", "타입 정보를 찾을 수 없어요."), + NOT_SUPPORTED_PAYMENT_TYPE(HttpStatus.BAD_REQUEST, "P007", "지원하지 않는 결제 수단이에요."), PAYMENT_UNEXPECTED_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "P998", "결제 과정중 예상치 못한 예외가 발생했어요."), PAYMENT_PROVIDER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "P999", "시스템에 일시적인 오류가 발생했어요. 잠시 후 다시 시도해주세요."), diff --git a/src/main/kotlin/roomescape/payment/implement/PaymentFinderV2.kt b/src/main/kotlin/roomescape/payment/implement/PaymentFinderV2.kt new file mode 100644 index 00000000..8b2a5a7f --- /dev/null +++ b/src/main/kotlin/roomescape/payment/implement/PaymentFinderV2.kt @@ -0,0 +1,53 @@ +package roomescape.payment.implement + +import io.github.oshai.kotlinlogging.KLogger +import io.github.oshai.kotlinlogging.KotlinLogging +import org.springframework.stereotype.Component +import roomescape.payment.exception.PaymentErrorCode +import roomescape.payment.exception.PaymentException +import roomescape.payment.infrastructure.persistence.v2.CanceledPaymentEntityV2 +import roomescape.payment.infrastructure.persistence.v2.CanceledPaymentRepositoryV2 +import roomescape.payment.infrastructure.persistence.v2.PaymentDetailEntity +import roomescape.payment.infrastructure.persistence.v2.PaymentDetailRepository +import roomescape.payment.infrastructure.persistence.v2.PaymentEntityV2 +import roomescape.payment.infrastructure.persistence.v2.PaymentRepositoryV2 + +private val log: KLogger = KotlinLogging.logger {} + +@Component +class PaymentFinderV2( + private val paymentRepository: PaymentRepositoryV2, + private val paymentDetailRepository: PaymentDetailRepository, + private val canceledPaymentRepository: CanceledPaymentRepositoryV2 +) { + + fun findPaymentByReservationId(reservationId: Long): PaymentEntityV2 { + log.debug { "[PaymentFinderV2.findByReservationId] 시작: reservationId=$reservationId" } + + return paymentRepository.findByReservationId(reservationId)?.also { + log.debug { "[PaymentFinderV2.findByReservationId] 완료: reservationId=$reservationId, paymentId=${it.id}" } + } ?: run { + log.warn { "[PaymentFinderV2.findByReservationId] 실패: reservationId=$reservationId" } + throw PaymentException(PaymentErrorCode.PAYMENT_NOT_FOUND) + } + } + + fun findPaymentDetailByPaymentId(paymentId: Long): PaymentDetailEntity { + log.debug { "[PaymentFinderV2.findPaymentDetailByPaymentId] 시작: paymentId=$paymentId" } + + return paymentDetailRepository.findByPaymentId(paymentId)?.also { + log.debug { "[PaymentFinderV2.findPaymentDetailByPaymentId] 완료: paymentId=$paymentId, detailId=${it.id}" } + } ?: run { + log.warn { "[PaymentFinderV2.findPaymentDetailByPaymentId] 실패: paymentId=$paymentId" } + throw PaymentException(PaymentErrorCode.PAYMENT_DETAIL_NOT_FOUND) + } + } + + fun findCanceledPaymentByPaymentIdOrNull(paymentId: Long): CanceledPaymentEntityV2? { + log.debug { "[PaymentFinderV2.findCanceledPaymentByKey] 시작: paymentId=$paymentId" } + + return canceledPaymentRepository.findByPaymentId(paymentId)?.also { + log.debug { "[PaymentFinderV2.findCanceledPaymentByKey] 완료: paymentId=$paymentId, canceledPaymentId=${it.id}" } + } + } +} diff --git a/src/main/kotlin/roomescape/payment/infrastructure/persistence/v2/CanceledPaymentRepositoryV2.kt b/src/main/kotlin/roomescape/payment/infrastructure/persistence/v2/CanceledPaymentRepositoryV2.kt index 41d6ff65..59814c7e 100644 --- a/src/main/kotlin/roomescape/payment/infrastructure/persistence/v2/CanceledPaymentRepositoryV2.kt +++ b/src/main/kotlin/roomescape/payment/infrastructure/persistence/v2/CanceledPaymentRepositoryV2.kt @@ -2,4 +2,6 @@ package roomescape.payment.infrastructure.persistence.v2 import org.springframework.data.jpa.repository.JpaRepository -interface CanceledPaymentRepositoryV2 : JpaRepository \ No newline at end of file +interface CanceledPaymentRepositoryV2 : JpaRepository { + fun findByPaymentId(paymentId: Long): CanceledPaymentEntityV2? +} diff --git a/src/main/kotlin/roomescape/payment/infrastructure/persistence/v2/PaymentDetailRepository.kt b/src/main/kotlin/roomescape/payment/infrastructure/persistence/v2/PaymentDetailRepository.kt index 68723420..516b7d04 100644 --- a/src/main/kotlin/roomescape/payment/infrastructure/persistence/v2/PaymentDetailRepository.kt +++ b/src/main/kotlin/roomescape/payment/infrastructure/persistence/v2/PaymentDetailRepository.kt @@ -2,4 +2,6 @@ package roomescape.payment.infrastructure.persistence.v2 import org.springframework.data.jpa.repository.JpaRepository -interface PaymentDetailRepository: JpaRepository \ No newline at end of file +interface PaymentDetailRepository: JpaRepository { + fun findByPaymentId(paymentId: Long) : PaymentDetailEntity? +}