summaryrefslogtreecommitdiff
path: root/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
diff options
context:
space:
mode:
authorms <ms@taler.net>2021-08-07 17:07:57 +0200
committerms <ms@taler.net>2021-08-07 17:10:20 +0200
commit575613d4d9f4c63a07ed22f245944f5b34214a8b (patch)
tree86b2db8fcf35c6faaed33b87753f085c45c5b730 /sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
parent05ddacd80641db9ebd00ba6bb20aa8200c8b76f8 (diff)
downloadlibeufin-575613d4d9f4c63a07ed22f245944f5b34214a8b.tar.gz
libeufin-575613d4d9f4c63a07ed22f245944f5b34214a8b.tar.bz2
libeufin-575613d4d9f4c63a07ed22f245944f5b34214a8b.zip
Sandbox bank account API.
Adding endpoints to create bank accounts (no EBICS) and asking their balances.
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt')
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt20
1 files changed, 17 insertions, 3 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index 0d812300..aac82469 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -1,5 +1,6 @@
package tech.libeufin.sandbox
+import io.ktor.http.*
import org.jetbrains.exposed.sql.or
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
@@ -10,12 +11,25 @@ import tech.libeufin.util.RawPayment
import tech.libeufin.util.importDateFromMillis
import tech.libeufin.util.parseDecimal
import tech.libeufin.util.toDashedDate
+import java.math.BigDecimal
private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox")
-fun balanceForAccount(iban: String): java.math.BigDecimal {
+fun getAccountFromLabel(accountLabel: String): BankAccountEntity {
+ return transaction {
+ val account = BankAccountEntity.find {
+ BankAccountsTable.label eq accountLabel
+ }.firstOrNull()
+ if (account == null) throw SandboxError(
+ HttpStatusCode.NotFound, "Account '$accountLabel' not found"
+ )
+ account
+ }
+}
+
+fun balanceForAccount(iban: String): BigDecimal {
logger.debug("Calculating balance for account: ${iban}")
- var balance = java.math.BigDecimal.ZERO
+ var balance = BigDecimal.ZERO
transaction {
BankAccountTransactionsTable.select {
BankAccountTransactionsTable.creditorIban eq iban
@@ -35,7 +49,7 @@ fun balanceForAccount(iban: String): java.math.BigDecimal {
* the current CAMT generator happy. Negative amounts need to have their
* onw sub-tree in the report, see bug: #6962
*/
- if (balance < java.math.BigDecimal.ZERO) return java.math.BigDecimal.ZERO
+ if (balance < BigDecimal.ZERO) return BigDecimal.ZERO
return balance
}