gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: fetching transactions


From: gnunet
Subject: [libeufin] branch master updated: fetching transactions
Date: Fri, 29 May 2020 17:10:28 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 5659a6f  fetching transactions
5659a6f is described below

commit 5659a6ff42df0683b46fc51c3af39ae68552badb
Author: MS <ms@taler.net>
AuthorDate: Fri May 29 17:08:38 2020 +0200

    fetching transactions
    
    This logic is now abstracted in a separate function
    so that it is easier to schedule it to implement a
    background history downloader.
---
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 91 ++++++++++++++---------
 1 file changed, 56 insertions(+), 35 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index bf05df8..68665a2 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -253,6 +253,54 @@ suspend fun schedulePeriodicWork() {
     }
 }
 
+suspend fun fetchTransactionsInternal(
+    client: HttpClient,
+    user: NexusUserEntity,
+    accountid: String,
+    ct: CollectedTransaction
+) {
+    val res = transaction {
+        val acct = NexusBankAccountEntity.findById(accountid)
+        if (acct == null) {
+            throw NexusError(
+                HttpStatusCode.NotFound,
+                "Account not found"
+            )
+        }
+        val conn = acct.defaultBankConnection
+        if (conn == null) {
+            throw NexusError(
+                HttpStatusCode.BadRequest,
+                "No default bank connection (explicit connection not yet 
supported)"
+            )
+        }
+        val subscriberDetails = getEbicsSubscriberDetails(user.id.value, 
conn.id.value)
+        return@transaction object {
+            val connectionType = conn.type
+            val connectionName = conn.id.value
+            val userId = user.id.value
+            val subscriberDetails = subscriberDetails
+        }
+    }
+    when (res.connectionType) {
+        "ebics" -> {
+            fetchEbicsC5x(
+                "C53",
+                client,
+                res.connectionName,
+                ct.start,
+                ct.end,
+                res.subscriberDetails
+            )
+            ingestBankMessagesIntoAccount(res.connectionName, accountid)
+        }
+        else -> throw NexusError(
+            HttpStatusCode.BadRequest,
+            "Connection type '${res.connectionType}' not implemented"
+        )
+    }
+}
+
 fun serverMain(dbName: String) {
     dbCreateTables(dbName)
     val client = HttpClient {
@@ -555,45 +603,18 @@ fun serverMain(dbName: String) {
                         "Account id missing"
                     )
                 }
-                val res = transaction {
-                    val user = authenticateRequest(call.request)
-                    val acct = NexusBankAccountEntity.findById(accountid)
-                    if (acct == null) {
-                        throw NexusError(
-                            HttpStatusCode.NotFound,
-                            "Account not found"
-                        )
-                    }
-                    val conn = acct.defaultBankConnection
-                    if (conn == null) {
-                        throw NexusError(
-                            HttpStatusCode.BadRequest,
-                            "No default bank connection (explicit connection 
not yet supported)"
-                        )
-                    }
-                    val subscriberDetails = 
getEbicsSubscriberDetails(user.id.value, conn.id.value)
-                    return@transaction object {
-                        val connectionType = conn.type
-                        val connectionName = conn.id.value
-                        val userId = user.id.value
-                        val subscriberDetails = subscriberDetails
-                    }
-                }
-                val request = if (call.request.hasBody()) {
+                val user = transaction { authenticateRequest(call.request) }
+                val ct = if (call.request.hasBody()) {
                     call.receive<CollectedTransaction>()
                 } else {
                     CollectedTransaction(null, null, null)
                 }
-                when (res.connectionType) {
-                    "ebics" -> {
-                        fetchEbicsC5x("C53",client, res.connectionName, 
request.start, request.end, res.subscriberDetails)
-                        ingestBankMessagesIntoAccount(res.connectionName, 
accountid)
-                    }
-                    else -> throw NexusError(
-                        HttpStatusCode.BadRequest,
-                        "Connection type '${res.connectionType}' not 
implemented"
-                    )
-                }
+                fetchTransactionsInternal(
+                    client,
+                    user,
+                    accountid,
+                    ct
+                )
                 call.respondText("Collection performed")
                 return@post
             }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]