diff options
author | MS <ms@taler.net> | 2020-05-14 20:57:45 +0200 |
---|---|---|
committer | MS <ms@taler.net> | 2020-05-14 20:57:45 +0200 |
commit | dee6d7b62215972e958a8a5e03242d11e22117b9 (patch) | |
tree | 0e58c4ff93e601d7749a6581176b0f347d970182 /nexus/src/main | |
parent | 081f9a4f105c6f2855a382df09dab5eea4bf4fb9 (diff) | |
download | libeufin-dee6d7b62215972e958a8a5e03242d11e22117b9.tar.gz libeufin-dee6d7b62215972e958a8a5e03242d11e22117b9.tar.bz2 libeufin-dee6d7b62215972e958a8a5e03242d11e22117b9.zip |
Moving DB statements inside transaction block.
Diffstat (limited to 'nexus/src/main')
-rw-r--r-- | nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt index aa73709a..15b4a8b1 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -280,19 +280,22 @@ fun main() { /** * Submit one particular payment at the bank. */ - post("/bank-accounts/{accountid}/prepared-payments/submit") { + post("/bank-accounts/prepared-payments/submit") { val userId = authenticateRequest(call.request.headers["Authorization"]) val body = call.receive<SubmitPayment>() val preparedPayment = getPreparedPayment(body.uuid) - if (preparedPayment.nexusUser.id.value != userId) throw NexusError( - HttpStatusCode.Forbidden, - "No rights over such payment" - ) - if (preparedPayment.submitted) { - throw NexusError( - HttpStatusCode.PreconditionFailed, - "Payment ${body.uuid} was submitted already" + transaction { + if (preparedPayment.nexusUser.id.value != userId) throw NexusError( + HttpStatusCode.Forbidden, + "No rights over such payment" ) + if (preparedPayment.submitted) { + throw NexusError( + HttpStatusCode.PreconditionFailed, + "Payment ${body.uuid} was submitted already" + ) + } + } val pain001document = createPain001document(preparedPayment) if (body.transport != null) { @@ -314,7 +317,9 @@ fun main() { client, userId, null, pain001document ) } - preparedPayment.submitted = true + transaction { + preparedPayment.submitted = true + } call.respondText("Payment ${body.uuid} submitted") return@post } |