gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (fc800dae -> 225bc67c)


From: gnunet
Subject: [libeufin] branch master updated (fc800dae -> 225bc67c)
Date: Tue, 11 Jan 2022 13:32:07 +0100

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

ms pushed a change to branch master
in repository libeufin.

    from fc800dae SPA
     new 036598c3 remove unused definition
     new 225bc67c implement history API

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    | 19 +++++++++++
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  | 39 ++++++++++++++++------
 2 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index 6e86b844..caf82ad5 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -338,10 +338,21 @@ object BankAccountTransactionsTable : LongIdTable() {
 class BankAccountTransactionEntity(id: EntityID<Long>) : LongEntity(id) {
     companion object : 
LongEntityClass<BankAccountTransactionEntity>(BankAccountTransactionsTable) {
         override fun new(init: BankAccountTransactionEntity.() -> Unit): 
BankAccountTransactionEntity {
+            /**
+             * Fresh transactions are those that wait to be included in a
+             * "history" report, likely a Camt.5x message.  The "fresh 
transactions"
+             * table keeps a list of such transactions.
+             */
             val freshTx = super.new(init)
             BankAccountFreshTransactionsTable.insert {
                 it[transactionRef] = freshTx.id
             }
+            /**
+             * The bank account involved in this transaction points to
+             * it as the "last known" transaction, to make it easier to
+             * build histories that depend on such record.
+             */
+            freshTx.account.lastTransaction = freshTx
             return freshTx
         }
     }
@@ -384,6 +395,13 @@ object BankAccountsTable : IntIdTable() {
     val owner = text("owner")
     val isPublic = bool("isPublic").default(false)
     val demoBank = reference("demoBank", DemobankConfigsTable)
+
+    /**
+     * Point to the last transaction related to this account, regardless
+     * of it being credit or debit.  This reference helps to construct
+     * history results that start from / depend on the last transaction.
+     */
+    val lastTransaction = reference("lastTransaction", 
BankAccountTransactionsTable).nullable()
 }
 
 class BankAccountEntity(id: EntityID<Int>) : IntEntity(id) {
@@ -395,6 +413,7 @@ class BankAccountEntity(id: EntityID<Int>) : IntEntity(id) {
     var owner by BankAccountsTable.owner
     var isPublic by BankAccountsTable.isPublic
     var demoBank by DemobankConfigEntity referencedOn 
BankAccountsTable.demoBank
+    var lastTransaction by BankAccountTransactionEntity optionalReferencedOn 
BankAccountsTable.lastTransaction
 }
 
 object BankAccountStatementsTable : IntIdTable() {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 6e6e4523..a74fd970 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -357,10 +357,6 @@ data class BankAccountInfo(
     val bic: String,
 )
 
-data class BankAccountsListReponse(
-    val accounts: List<BankAccountInfo>
-)
-
 inline fun <reified T> Document.toObject(): T {
     val jc = JAXBContext.newInstance(T::class.java)
     val m = jc.createUnmarshaller()
@@ -1283,7 +1279,7 @@ val sandboxApp: Application.() -> Unit = {
                     })
                     return@get
                 }
-                get("/accounts/{account_name}/history") {
+                get("/accounts/{account_name}/transactions") {
                     val demobank = ensureDemobank(call)
                     val bankAccount = getBankAccountFromLabel(
                         call.getUriComponent("account_name"),
@@ -1293,13 +1289,36 @@ val sandboxApp: Application.() -> Unit = {
                     if (!authOk && (call.request.basicAuth() != 
bankAccount.owner)) throw forbidden(
                         "Cannot access bank account ${bankAccount.label}"
                     )
+
+                    val page: Int = 
Integer.decode(call.request.queryParameters["page"] ?: "1")
+                    val size: Int = 
Integer.decode(call.request.queryParameters["size"] ?: "5")
+
                     val ret = mutableListOf<RawPayment>()
+                    /**
+                     * Case where page number wasn't given,
+                     * therefore the results starts from the last transaction. 
*/
                     transaction {
-                        BankAccountTransactionEntity.find {
-                            BankAccountTransactionsTable.account eq 
bankAccount.id
-                            // FIXME: more criteria to come.
-                        }.forEach {
-                            ret.add(getHistoryElementFromTransactionRow(it))
+                        /**
+                         * Get a history page - from the calling bank account 
- having
+                         * 'firstElementId' as the latest transaction in it.  
*/
+                        fun getPage(firstElementId: Long): 
Iterable<BankAccountTransactionEntity> {
+                            return BankAccountTransactionEntity.find {
+                                (BankAccountTransactionsTable.id lessEq 
firstElementId) and
+                                        (BankAccountTransactionsTable.account 
eq bankAccount.id)
+                            }.take(size)
+                        }
+                        val lt: BankAccountTransactionEntity? = 
bankAccount.lastTransaction
+                        if (lt == null) return@transaction
+                        var firstElement: BankAccountTransactionEntity = lt
+                        /**
+                         * This loop fetches (and discards) pages until the
+                         * desired one is found.  */
+                        for (i in 0..(page)) {
+                            val pageBuf = getPage(firstElement.id.value)
+                            firstElement = pageBuf.last()
+                            if (i == page) pageBuf.forEach {
+                                
ret.add(getHistoryElementFromTransactionRow(it))
+                            }
                         }
                     }
                     call.respond(ret)

-- 
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]