-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from holixon/19-deposit-money-to-bank-account
19 - deposit money to bank account
- Loading branch information
Showing
42 changed files
with
457 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...in/io/holixon/cqrshexagonaldemo/demoparent/transactions/adapter/GlobalExceptionHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.transactions.adapter | ||
|
||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.exception.AccountNotFoundException | ||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.exception.InvalidInputException | ||
import jakarta.servlet.http.HttpServletRequest | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.ExceptionHandler | ||
import org.springframework.web.bind.annotation.RestControllerAdvice | ||
|
||
@RestControllerAdvice | ||
class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(AccountNotFoundException::class) | ||
fun handleException(request: HttpServletRequest, exception: AccountNotFoundException): ResponseEntity<Unit> { | ||
return ResponseEntity.notFound().build() | ||
} | ||
|
||
@ExceptionHandler(InvalidInputException::class) | ||
fun handleException(request: HttpServletRequest, exception: InvalidInputException): ResponseEntity<Unit> { | ||
return ResponseEntity.badRequest().build() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...onaldemo/demoparent/transactions/application/port/inbound/account/DepositAccountInPort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.transactions.application.port.inbound.account | ||
|
||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.model.account.Amount | ||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.model.account.Iban | ||
|
||
interface DepositAccountInPort { | ||
fun deposit(iban: Iban, amount: Amount) | ||
} |
4 changes: 3 additions & 1 deletion
4
...hexagonaldemo/demoparent/transactions/application/port/outbound/account/AccountOutPort.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.transactions.application.port.outbound.account | ||
|
||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.model.account.Account | ||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.model.account.Amount | ||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.model.account.Iban | ||
|
||
interface AccountOutPort { | ||
fun findAccount(iban: Iban): Account? | ||
fun findAccount(iban: Iban): Account | ||
fun createAccount(account: Account): Account | ||
fun deposit(account: Account, amount: Amount): Account | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...o/holixon/cqrshexagonaldemo/demoparent/transactions/application/usecase/DepositUsecase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.transactions.application.usecase | ||
|
||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.application.port.inbound.account.DepositAccountInPort | ||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.application.port.outbound.account.AccountOutPort | ||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.application.port.outbound.eventing.EventingOutAdapter | ||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.model.account.Amount | ||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.model.account.Iban | ||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.model.event.MoneyDepositedEvent | ||
import io.holixon.cqrshexagonaldemo.demoparent.transactions.framework.Usecase | ||
import mu.KLogging | ||
|
||
@Usecase | ||
class DepositUsecase( | ||
private val accountOutPort: AccountOutPort, | ||
private val eventingOutAdapter: EventingOutAdapter | ||
) : DepositAccountInPort { | ||
|
||
companion object : KLogging() | ||
|
||
override fun deposit(iban: Iban, amount: Amount) { | ||
logger().info { "deposit $amount to account ${iban.value}" } | ||
|
||
val account = accountOutPort.findAccount(iban) | ||
|
||
val updatedAccount = accountOutPort.deposit(account, amount) | ||
|
||
eventingOutAdapter.publishEvent(MoneyDepositedEvent( | ||
updatedAccount.iban, | ||
updatedAccount.balance, | ||
System.currentTimeMillis() | ||
)) | ||
|
||
logger().info { "updated account $updatedAccount" } | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
...on/cqrshexagonaldemo/demoparent/transactions/domain/exception/AccountNotFoundException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.exception | ||
|
||
class AccountNotFoundException(message: String) : RuntimeException(message) |
3 changes: 3 additions & 0 deletions
3
...lixon/cqrshexagonaldemo/demoparent/transactions/domain/exception/InvalidInputException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.exception | ||
|
||
class InvalidInputException(message: String) : RuntimeException(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...otlin/io/holixon/cqrshexagonaldemo/demoparent/transactions/domain/model/account/Amount.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.model.account | ||
|
||
import java.math.BigDecimal | ||
|
||
/** | ||
* For now this class can be value class in future when currency is introduced must be revised to support currency | ||
*/ | ||
@JvmInline | ||
value class Amount(val value: BigDecimal) { | ||
init { | ||
require(value >= BigDecimal.ZERO){ | ||
"Amount must be positive" | ||
} | ||
} | ||
|
||
operator fun plus(value2: Amount) : Amount { | ||
return Amount(this.value.plus(value2.value)) | ||
} | ||
|
||
override fun toString(): String { | ||
return value.toString() | ||
} | ||
} |
7 changes: 6 additions & 1 deletion
7
.../kotlin/io/holixon/cqrshexagonaldemo/demoparent/transactions/domain/model/account/Iban.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
package io.holixon.cqrshexagonaldemo.demoparent.transactions.domain.model.account | ||
|
||
@JvmInline | ||
value class Iban(val value: String) | ||
value class Iban(val value: String) { | ||
|
||
override fun toString(): String { | ||
return value | ||
} | ||
} |
Oops, something went wrong.