Skip to content

Commit

Permalink
refactor: payment > application 계층 presentation dto 의존 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy.lee committed Oct 24, 2023
1 parent 8559262 commit 166e2d9
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,17 @@ package com.hanghae.commerce.payment.application
import com.hanghae.commerce.order.domain.OrderReader
import com.hanghae.commerce.payment.domain.PaymentService
import com.hanghae.commerce.payment.domain.command.PaymentCommand
import com.hanghae.commerce.payment.presentation.dto.PaymentRequest
import com.hanghae.commerce.payment.presentation.dto.PaymentResponse
import org.springframework.stereotype.Component

@Component
class PaymentFacade(
private val paymentService: PaymentService,
private val orderReader: OrderReader,
) {
fun payment(paymentRequest: PaymentRequest): PaymentResponse {
return PaymentResponse(
paymentService.payment(
PaymentCommand(
order = orderReader.read(paymentRequest.orderId),
bankAccount = paymentRequest.bankAccount,
),
),
fun payment(command: PaymentCommand): String {
return paymentService.payment(
command,
orderReader.read(command.orderId),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class PaymentService(
@CircuitBreaker(name = "payment", fallbackMethod = "circuitBreakerFallback")
fun payment(
command: PaymentCommand,
order: Order,
): String {
val order = command.order
if (!order.isPaymentWait()) {
throw IllegalStateException("이미 결제가 완료된 주문입니다.")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.hanghae.commerce.payment.domain.command

import com.hanghae.commerce.order.domain.Order
import com.hanghae.commerce.payment.domain.BankAccount

data class PaymentCommand(
val order: Order,
val orderId: String,
val bankAccount: BankAccount,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hanghae.commerce.payment.presentation

import com.hanghae.commerce.payment.application.PaymentFacade
import com.hanghae.commerce.payment.domain.command.PaymentCommand
import com.hanghae.commerce.payment.presentation.dto.PaymentRequest
import com.hanghae.commerce.payment.presentation.dto.PaymentResponse
import jakarta.validation.Valid
Expand All @@ -22,7 +23,14 @@ class PaymentController(
paymentRequest: PaymentRequest,
): ResponseEntity<PaymentResponse> {
return ResponseEntity.ok(
paymentFacade.payment(paymentRequest),
PaymentResponse(
paymentFacade.payment(
PaymentCommand(
paymentRequest.orderId,
paymentRequest.bankAccount,
),
),
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class OrderCancelServiceTest {
private lateinit var sut: OrderCancelService

@Nested
@DisplayName("When: 주문 취소가 성공하면, ")
@DisplayName("When: 주문 취소가 성공하면")
inner class Context1 {

Check failure on line 35 in commerce-api/src/test/kotlin/com/hanghae/commerce/claim/domain/OrderCancelServiceTest.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] commerce-api/src/test/kotlin/com/hanghae/commerce/claim/domain/OrderCancelServiceTest.kt#L35 <standard:no-empty-first-line-in-class-body>

Class body should not start with blank line
Raw output
commerce-api/src/test/kotlin/com/hanghae/commerce/claim/domain/OrderCancelServiceTest.kt:35:1: error: Class body should not start with blank line (standard:no-empty-first-line-in-class-body)
val testOrderId = "testOrderId"
Expand Down Expand Up @@ -64,7 +64,7 @@ class OrderCancelServiceTest {
}

@Test
@DisplayName("Then: 저장소에 저장한다.")
@DisplayName("Then: 변경사항을 저장소에 저장한다.")
fun tc3() {
// when
sut.cancel(command, order)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OrderCancelValidatorTest {
private lateinit var sut: OrderCancelValidator

@Nested
@DisplayName("When: 환불시 환불 전용 계좌를 입력했다면,")
@DisplayName("When: 환불시 환불 전용 계좌를 입력했을 때")
inner class Context1 {
@Test
@DisplayName("Then: 계좌의 유효성을 검증한다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ClaimControllerTest {
val itemId = "testItemId"
val orderId = "testOrderId"
val item = persistItem(itemId, "상품1", 10000, 10, "1")
val order = persistOrder(userId, orderId, item)
persistOrder(userId, orderId, item)

// when
val request = OrderCancelRequest(

Check failure on line 57 in commerce-api/src/test/kotlin/com/hanghae/commerce/claim/presentation/ClaimControllerTest.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] commerce-api/src/test/kotlin/com/hanghae/commerce/claim/presentation/ClaimControllerTest.kt#L57 <standard:multiline-expression-wrapping>

A multiline expression should start on a new line
Raw output
commerce-api/src/test/kotlin/com/hanghae/commerce/claim/presentation/ClaimControllerTest.kt:57:23: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ class PaymentServiceTest {

private fun executePayment(alreadyPayedOrder: Order): String {
return sut.payment(
PaymentCommand(
order = alreadyPayedOrder,
command = PaymentCommand(

Check failure on line 79 in commerce-api/src/test/kotlin/com/hanghae/commerce/payment/domain/PaymentServiceTest.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] commerce-api/src/test/kotlin/com/hanghae/commerce/payment/domain/PaymentServiceTest.kt#L79 <standard:multiline-expression-wrapping>

A multiline expression should start on a new line
Raw output
commerce-api/src/test/kotlin/com/hanghae/commerce/payment/domain/PaymentServiceTest.kt:79:23: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
orderId = alreadyPayedOrder.id,
bankAccount = BankAccount(

Check failure on line 81 in commerce-api/src/test/kotlin/com/hanghae/commerce/payment/domain/PaymentServiceTest.kt

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] commerce-api/src/test/kotlin/com/hanghae/commerce/payment/domain/PaymentServiceTest.kt#L81 <standard:multiline-expression-wrapping>

A multiline expression should start on a new line
Raw output
commerce-api/src/test/kotlin/com/hanghae/commerce/payment/domain/PaymentServiceTest.kt:81:31: error: A multiline expression should start on a new line (standard:multiline-expression-wrapping)
bankName = "국민은행",
accountNumber = "1234567890",
accountHolder = "홍길동",
),
),
order = alreadyPayedOrder,
)
}

Expand Down

0 comments on commit 166e2d9

Please sign in to comment.