From 1be0893932d84c59f8d2bfd1b7d38bded6d1d350 Mon Sep 17 00:00:00 2001 From: jihye-woo Date: Sat, 5 Nov 2022 08:57:06 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B3=84?= =?UTF-8?q?=EC=B8=B5=20->=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EA=B5=AC=EA=B0=84=20=EB=A7=A4=ED=95=91=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../buckpal/account/adapter/in/web/SendMoneyController.kt | 5 +++-- .../account/application/port/in/SendMoneyUseCase.kt | 4 +++- .../account/application/service/SendMoneyResult.kt | 5 +++++ .../account/application/service/SendMoneyService.kt | 8 ++++---- 4 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyResult.kt diff --git a/src/main/kotlin/backendsquid/buckpal/account/adapter/in/web/SendMoneyController.kt b/src/main/kotlin/backendsquid/buckpal/account/adapter/in/web/SendMoneyController.kt index 09cb65b..da6129d 100644 --- a/src/main/kotlin/backendsquid/buckpal/account/adapter/in/web/SendMoneyController.kt +++ b/src/main/kotlin/backendsquid/buckpal/account/adapter/in/web/SendMoneyController.kt @@ -2,6 +2,7 @@ package backendsquid.buckpal.account.adapter.`in`.web import backendsquid.buckpal.account.application.port.`in`.SendMoneyCommand import backendsquid.buckpal.account.application.port.`in`.SendMoneyUseCase +import backendsquid.buckpal.account.application.service.SendMoneyResult import org.springframework.validation.annotation.Validated import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.PostMapping @@ -21,7 +22,7 @@ class SendMoneyController( @PathVariable("sourceAccountId") @Positive sourceAccountId: Long, @PathVariable("targetAccountId") @Positive targetAccountId: Long, @PathVariable("amount") @Positive amount: Long, - ): Boolean { + ): SendMoneyResult { val command = SendMoneyCommand( sourceAccountId = sourceAccountId, targetAccountId = targetAccountId, @@ -34,7 +35,7 @@ class SendMoneyController( @PostMapping("/accounts/send") fun sendMoneyByBody( @RequestBody @Valid sendMoneyResource: SendMoneyResource - ): Boolean { + ): SendMoneyResult { val command = SendMoneyCommand( sourceAccountId = sendMoneyResource.sourceAccountId, targetAccountId = sendMoneyResource.targetAccountId, diff --git a/src/main/kotlin/backendsquid/buckpal/account/application/port/in/SendMoneyUseCase.kt b/src/main/kotlin/backendsquid/buckpal/account/application/port/in/SendMoneyUseCase.kt index 8df9e25..2a4c020 100644 --- a/src/main/kotlin/backendsquid/buckpal/account/application/port/in/SendMoneyUseCase.kt +++ b/src/main/kotlin/backendsquid/buckpal/account/application/port/in/SendMoneyUseCase.kt @@ -1,5 +1,7 @@ package backendsquid.buckpal.account.application.port.`in` +import backendsquid.buckpal.account.application.service.SendMoneyResult + interface SendMoneyUseCase { - fun sendMoney(command: SendMoneyCommand): Boolean + fun sendMoney(command: SendMoneyCommand): SendMoneyResult } diff --git a/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyResult.kt b/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyResult.kt new file mode 100644 index 0000000..415efc8 --- /dev/null +++ b/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyResult.kt @@ -0,0 +1,5 @@ +package backendsquid.buckpal.account.application.service + +data class SendMoneyResult( + val boolean : Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyService.kt b/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyService.kt index fa4c899..5d23bbc 100644 --- a/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyService.kt +++ b/src/main/kotlin/backendsquid/buckpal/account/application/service/SendMoneyService.kt @@ -16,7 +16,7 @@ class SendMoneyService( private val accountLock: AccountLock, private val updateAccountStatePort: UpdateAccountStatePort, ): SendMoneyUseCase { - override fun sendMoney(command: SendMoneyCommand): Boolean { + override fun sendMoney(command: SendMoneyCommand): SendMoneyResult { val baseline = LocalDateTime.now().minusDays(10) val sourceAccount = loadAccountPort.loadAccount( accountId = command.sourceAccountId, @@ -30,13 +30,13 @@ class SendMoneyService( accountLock.lockAccount(sourceAccount.id) if (!sourceAccount.withdraw(money = command.money, targetAccountId = targetAccount.id)) { accountLock.releaseAccount(sourceAccount.id) - return false + return SendMoneyResult(false) } accountLock.lockAccount(targetAccount.id) if (!targetAccount.deposit(money = command.money, sourceAccountId = sourceAccount.id)) { accountLock.releaseAccount(targetAccount.id) - return false + return SendMoneyResult(false) } updateAccountStatePort.updateActivities(sourceAccount) @@ -45,6 +45,6 @@ class SendMoneyService( accountLock.releaseAccount(sourceAccount.id) accountLock.releaseAccount(targetAccount.id) - return true + return SendMoneyResult(true) } }