From 9fe576af1161150ba1b72f7ee14fedb53ebd9336 Mon Sep 17 00:00:00 2001 From: pricelees Date: Thu, 16 Oct 2025 15:29:20 +0900 Subject: [PATCH] =?UTF-8?q?remove:=20OrderService=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=ED=99=94=EB=A1=9C=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EA=B2=8C=20=EB=90=9C=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/OrderPostProcessorService.kt | 60 ------------------- .../order/exception/OrderExceptionHandler.kt | 45 -------------- .../persistence/PaymentAttemptEntity.kt | 38 ------------ .../persistence/PaymentAttemptRepository.kt | 28 --------- .../persistence/PostOrderTaskEntity.kt | 16 ----- .../persistence/PostOrderTaskRepository.kt | 6 -- .../roomescape/payment/dto/PaymentWriteDTO.kt | 5 -- 7 files changed, 198 deletions(-) delete mode 100644 service/src/main/kotlin/com/sangdol/roomescape/order/business/OrderPostProcessorService.kt delete mode 100644 service/src/main/kotlin/com/sangdol/roomescape/order/exception/OrderExceptionHandler.kt delete mode 100644 service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptEntity.kt delete mode 100644 service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptRepository.kt delete mode 100644 service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskEntity.kt delete mode 100644 service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskRepository.kt diff --git a/service/src/main/kotlin/com/sangdol/roomescape/order/business/OrderPostProcessorService.kt b/service/src/main/kotlin/com/sangdol/roomescape/order/business/OrderPostProcessorService.kt deleted file mode 100644 index f2fde854..00000000 --- a/service/src/main/kotlin/com/sangdol/roomescape/order/business/OrderPostProcessorService.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.sangdol.roomescape.order.business - -import com.sangdol.common.persistence.IDGenerator -import com.sangdol.common.persistence.TransactionExecutionUtil -import com.sangdol.roomescape.order.infrastructure.persistence.PostOrderTaskEntity -import com.sangdol.roomescape.order.infrastructure.persistence.PostOrderTaskRepository -import com.sangdol.roomescape.payment.business.PaymentService -import com.sangdol.roomescape.payment.dto.PaymentGatewayResponse -import com.sangdol.roomescape.reservation.business.ReservationService -import io.github.oshai.kotlinlogging.KLogger -import io.github.oshai.kotlinlogging.KotlinLogging -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Propagation -import org.springframework.transaction.annotation.Transactional -import java.time.Instant - -private val log: KLogger = KotlinLogging.logger {} - -@Service -class OrderPostProcessorService( - private val idGenerator: IDGenerator, - private val reservationService: ReservationService, - private val paymentService: PaymentService, - private val postOrderTaskRepository: PostOrderTaskRepository, - private val transactionExecutionUtil: TransactionExecutionUtil -) { - @Transactional(propagation = Propagation.REQUIRES_NEW) - fun processAfterPaymentConfirmation( - reservationId: Long, - paymentResponse: PaymentGatewayResponse - ) { - val paymentKey = paymentResponse.paymentKey - try { - log.info { "[processAfterPaymentConfirmation] 결제 정보 저장 및 예약 확정 처리 시작: reservationId=${reservationId}, paymentKey=${paymentKey}" } - - val paymentCreateResponse = paymentService.savePayment(reservationId, paymentResponse) - reservationService.confirmReservation(reservationId) - - log.info { - "[processAfterPaymentConfirmation] 결제 정보 저장 및 예약 확정 처리 완료: reservationId=${reservationId}, paymentKey=${paymentKey}, paymentId=${paymentCreateResponse.paymentId}, paymentDetailId=${paymentCreateResponse.detailId}" - } - } catch (e: Exception) { - log.warn(e) { "[processAfterPaymentConfirmation] 결제 정보 저장 및 예약 확정 처리 실패. 작업 저장 시작: reservationId=${reservationId}, paymentKey=$paymentKey}" } - - transactionExecutionUtil.withNewTransaction(isReadOnly = false) { - PostOrderTaskEntity( - id = idGenerator.create(), - reservationId = reservationId, - paymentKey = paymentKey, - trial = 1, - nextRetryAt = Instant.now().plusSeconds(30), - ).also { - postOrderTaskRepository.save(it) - } - } - - log.info { "[processAfterPaymentConfirmation] 작업 저장 완료" } - } - } -} diff --git a/service/src/main/kotlin/com/sangdol/roomescape/order/exception/OrderExceptionHandler.kt b/service/src/main/kotlin/com/sangdol/roomescape/order/exception/OrderExceptionHandler.kt deleted file mode 100644 index 908450a3..00000000 --- a/service/src/main/kotlin/com/sangdol/roomescape/order/exception/OrderExceptionHandler.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.sangdol.roomescape.order.exception - -import com.sangdol.common.types.exception.ErrorCode -import com.sangdol.common.types.web.HttpStatus -import com.sangdol.common.web.support.log.WebLogMessageConverter -import io.github.oshai.kotlinlogging.KLogger -import io.github.oshai.kotlinlogging.KotlinLogging -import jakarta.servlet.http.HttpServletRequest -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.ExceptionHandler -import org.springframework.web.bind.annotation.RestControllerAdvice - -private val log: KLogger = KotlinLogging.logger {} - -@RestControllerAdvice -class OrderExceptionHandler( - private val messageConverter: WebLogMessageConverter -) { - @ExceptionHandler(OrderException::class) - fun handleOrderException( - servletRequest: HttpServletRequest, - e: OrderException - ): ResponseEntity { - val errorCode: ErrorCode = e.errorCode - val httpStatus: HttpStatus = errorCode.httpStatus - val errorResponse = OrderErrorResponse( - code = errorCode.errorCode, - message = if (httpStatus.isClientError()) e.message else errorCode.message, - trial = e.trial - ) - - log.info { - messageConverter.convertToErrorResponseMessage( - servletRequest = servletRequest, - httpStatus = httpStatus, - responseBody = errorResponse, - exception = if (errorCode.message == e.message) null else e - ) - } - - return ResponseEntity - .status(httpStatus.value()) - .body(errorResponse) - } -} diff --git a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptEntity.kt b/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptEntity.kt deleted file mode 100644 index 26de715c..00000000 --- a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptEntity.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.sangdol.roomescape.order.infrastructure.persistence - -import com.sangdol.common.persistence.PersistableBaseEntity -import jakarta.persistence.* -import org.springframework.data.annotation.CreatedBy -import org.springframework.data.annotation.CreatedDate -import org.springframework.data.jpa.domain.support.AuditingEntityListener -import java.time.Instant - -@Entity -@EntityListeners(AuditingEntityListener::class) -@Table(name = "payment_attempts") -class PaymentAttemptEntity( - id: Long, - - val reservationId: Long, - - @Enumerated(value = EnumType.STRING) - val result: AttemptResult, - - @Column(columnDefinition = "VARCHAR(50)") - val errorCode: String? = null, - - @Column(columnDefinition = "TEXT") - val message: String? = null, -) : PersistableBaseEntity(id) { - @Column(updatable = false) - @CreatedDate - lateinit var createdAt: Instant - - @Column(updatable = false) - @CreatedBy - var createdBy: Long = 0L -} - -enum class AttemptResult { - SUCCESS, FAILED -} \ No newline at end of file diff --git a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptRepository.kt b/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptRepository.kt deleted file mode 100644 index 4f2ff58f..00000000 --- a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PaymentAttemptRepository.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.sangdol.roomescape.order.infrastructure.persistence - -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.Query - -interface PaymentAttemptRepository: JpaRepository { - - fun countByReservationId(reservationId: Long): Long - - @Query( - """ - SELECT - CASE - WHEN COUNT(pa) > 0 - THEN TRUE - ELSE FALSE - END - FROM - PaymentAttemptEntity pa - WHERE - pa.reservationId = :reservationId - AND pa.result = com.sangdol.roomescape.order.infrastructure.persistence.AttemptResult.SUCCESS - """ - ) - fun isSuccessAttemptExists(reservationId: Long): Boolean - - fun findAllByReservationId(reservationId: Long): List -} diff --git a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskEntity.kt b/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskEntity.kt deleted file mode 100644 index 730ca5c8..00000000 --- a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskEntity.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.sangdol.roomescape.order.infrastructure.persistence - -import com.sangdol.common.persistence.PersistableBaseEntity -import jakarta.persistence.Entity -import jakarta.persistence.Table -import java.time.Instant - -@Entity -@Table(name = "post_order_tasks") -class PostOrderTaskEntity( - id: Long, - val reservationId: Long, - val paymentKey: String, - val trial: Int, - val nextRetryAt: Instant -) : PersistableBaseEntity(id) \ No newline at end of file diff --git a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskRepository.kt b/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskRepository.kt deleted file mode 100644 index 356215e8..00000000 --- a/service/src/main/kotlin/com/sangdol/roomescape/order/infrastructure/persistence/PostOrderTaskRepository.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.sangdol.roomescape.order.infrastructure.persistence - -import org.springframework.data.jpa.repository.JpaRepository - -interface PostOrderTaskRepository : JpaRepository { -} \ No newline at end of file diff --git a/service/src/main/kotlin/com/sangdol/roomescape/payment/dto/PaymentWriteDTO.kt b/service/src/main/kotlin/com/sangdol/roomescape/payment/dto/PaymentWriteDTO.kt index 2d89c07c..e11d2b20 100644 --- a/service/src/main/kotlin/com/sangdol/roomescape/payment/dto/PaymentWriteDTO.kt +++ b/service/src/main/kotlin/com/sangdol/roomescape/payment/dto/PaymentWriteDTO.kt @@ -8,11 +8,6 @@ data class PaymentConfirmRequest( val amount: Int, ) -data class PaymentCreateResponse( - val paymentId: Long, - val detailId: Long -) - data class PaymentCancelRequest( val reservationId: Long, val cancelReason: String,