summaryrefslogtreecommitdiff
path: root/nexus/src/main/kotlin/tech/libeufin/nexus/server
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-04-03 01:32:14 +0200
committerMS <ms@taler.net>2023-04-03 01:32:14 +0200
commit9b0aafb5e814fbb4328392fbd28e80e04ca95a60 (patch)
tree099c2814e16cafd7720ba338f81b40463e227510 /nexus/src/main/kotlin/tech/libeufin/nexus/server
parentf16ab461f917b03dca44487c9d2c7b9084a7431c (diff)
downloadlibeufin-9b0aafb5e814fbb4328392fbd28e80e04ca95a60.tar.gz
libeufin-9b0aafb5e814fbb4328392fbd28e80e04ca95a60.tar.bz2
libeufin-9b0aafb5e814fbb4328392fbd28e80e04ca95a60.zip
comments, indentation, helpers
Diffstat (limited to 'nexus/src/main/kotlin/tech/libeufin/nexus/server')
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt9
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt12
2 files changed, 15 insertions, 6 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt
index 8c01705a..08eb2b1d 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt
@@ -1,11 +1,20 @@
package tech.libeufin.nexus.server
+import io.ktor.http.*
import org.jetbrains.exposed.sql.transactions.transaction
import tech.libeufin.nexus.NexusBankConnectionEntity
import tech.libeufin.nexus.NexusBankConnectionsTable
+import tech.libeufin.nexus.NexusError
import tech.libeufin.util.internalServerError
import tech.libeufin.util.notFound
+fun unknownBankAccount(bankAccountLabel: String): NexusError {
+ return NexusError(
+ HttpStatusCode.NotFound,
+ "Bank account $bankAccountLabel was not found"
+ )
+}
+
/**
* FIXME:
* enum type names were introduced after 0.9.2 and need to
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
index fb864d3b..03f12cf6 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -456,7 +456,7 @@ val nexusApp: Application.() -> Unit = {
resp.set<JsonNode>("schedule", ops)
transaction {
NexusBankAccountEntity.findByName(accountId)
- ?: throw NexusError(HttpStatusCode.NotFound, "unknown bank account")
+ ?: throw unknownBankAccount(accountId)
NexusScheduledTaskEntity.find {
(NexusScheduledTasksTable.resourceType eq "bank-account") and
(NexusScheduledTasksTable.resourceId eq accountId)
@@ -479,7 +479,7 @@ val nexusApp: Application.() -> Unit = {
val accountId = ensureNonNull(call.parameters["accountId"])
transaction {
NexusBankAccountEntity.findByName(accountId)
- ?: throw NexusError(HttpStatusCode.NotFound, "unknown bank account")
+ ?: throw unknownBankAccount(accountId)
try {
NexusCron.parser.parse(schedSpec.cronspec)
} catch (e: IllegalArgumentException) {
@@ -550,7 +550,7 @@ val nexusApp: Application.() -> Unit = {
transaction {
val bankAccount = NexusBankAccountEntity.findByName(accountId)
if (bankAccount == null) {
- throw NexusError(HttpStatusCode.NotFound, "unknown bank account")
+ throw unknownBankAccount(accountId)
}
val oldSchedTask = NexusScheduledTaskEntity.find {
(NexusScheduledTasksTable.taskName eq taskId) and
@@ -571,7 +571,7 @@ val nexusApp: Application.() -> Unit = {
val res = transaction {
val bankAccount = NexusBankAccountEntity.findByName(accountId)
if (bankAccount == null) {
- throw NexusError(HttpStatusCode.NotFound, "unknown bank account")
+ throw unknownBankAccount(accountId)
}
val holderEnc = URLEncoder.encode(bankAccount.accountHolder, Charsets.UTF_8)
val lastSeenBalance = NexusBankBalanceEntity.find {
@@ -693,7 +693,7 @@ val nexusApp: Application.() -> Unit = {
val res = transaction {
val bankAccount = NexusBankAccountEntity.findByName(accountId)
if (bankAccount == null) {
- throw NexusError(HttpStatusCode.NotFound, "unknown bank account ($accountId)")
+ throw unknownBankAccount(accountId)
}
val amount = parseAmount(body.amount)
val paymentEntity = addPaymentInitiation(
@@ -767,7 +767,7 @@ val nexusApp: Application.() -> Unit = {
transaction {
val bankAccount = NexusBankAccountEntity.findByName(bankAccountId)
if (bankAccount == null) {
- throw NexusError(HttpStatusCode.NotFound, "unknown bank account")
+ throw unknownBankAccount(bankAccountId)
}
NexusBankTransactionEntity.find { NexusBankTransactionsTable.bankAccount eq bankAccount.id }.map {
val tx = jacksonObjectMapper().readValue(