summaryrefslogtreecommitdiff
path: root/sandbox/src/main/kotlin/tech/libeufin
diff options
context:
space:
mode:
authorms <ms@taler.net>2023-03-22 16:23:29 +0100
committerms <ms@taler.net>2023-03-22 16:23:29 +0100
commit4887d87c0be652b21fcf6f2c6d6dde2b05dd4a66 (patch)
tree35e22b674f7ad8ef7d272ddca68bd7852c1c2fc4 /sandbox/src/main/kotlin/tech/libeufin
parent10bc544c731291090683bc67e421c1740f6dc269 (diff)
downloadlibeufin-4887d87c0be652b21fcf6f2c6d6dde2b05dd4a66.tar.gz
libeufin-4887d87c0be652b21fcf6f2c6d6dde2b05dd4a66.tar.bz2
libeufin-4887d87c0be652b21fcf6f2c6d6dde2b05dd4a66.zip
time ranged history (access API)
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin')
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt29
1 files changed, 17 insertions, 12 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 5bceaf6b..4d91257d 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -1482,34 +1482,39 @@ val sandboxApp: Application.() -> Unit = {
val authGranted: Boolean = bankAccount.isPublic || !WITH_AUTH || username == "admin"
if (!authGranted && bankAccount.owner != username)
throw forbidden("Cannot access bank account ${bankAccount.label}")
- val page: Int = Integer.decode(call.request.queryParameters["page"] ?: "0")
- val size: Int = Integer.decode(call.request.queryParameters["size"] ?: "5")
-
+ // Paging values.
+ val page: Int = expectInt(call.request.queryParameters["page"] ?: "1")
+ val size: Int = expectInt(call.request.queryParameters["size"] ?: "5")
+ // Time range filter values
+ val fromMs = expectLong(call.request.queryParameters["from_ms"] ?: "0")
+ val untilMs = expectLong(call.request.queryParameters["until_ms"] ?: Long.MAX_VALUE.toString())
val ret = mutableListOf<RawPayment>()
/**
* Case where page number wasn't given,
- * therefore the results starts from the last transaction. */
+ * therefore the results starts from the last transaction.
+ */
transaction {
/**
* Get a history page - from the calling bank account - having
* 'firstElementId' as the latest transaction in it. */
fun getPage(firstElementId: Long): Iterable<BankAccountTransactionEntity> {
- logger.debug("History page from tx $firstElementId, including $size txs in the past.")
+ logger.debug("Trying to build pageBuf from ID: $firstElementId," +
+ " including $size txs in the past."
+ )
return BankAccountTransactionEntity.find {
(BankAccountTransactionsTable.id lessEq firstElementId) and
- (BankAccountTransactionsTable.account eq bankAccount.id)
+ (BankAccountTransactionsTable.account eq bankAccount.id) and
+ (BankAccountTransactionsTable.date.between(fromMs, untilMs))
}.sortedByDescending { it.id.value }.take(size)
}
val lt: BankAccountTransactionEntity? = bankAccount.lastTransaction
if (lt == null) return@transaction
var nextPageIdUpperLimit: Long = lt.id.value
- /**
- * This loop fetches (and discards) pages until the
- * desired one is found. */
- for (i in 0..(page)) {
+ // This loop fetches (and discards) pages until the desired one is found.
+ for (i in 1..(page)) {
val pageBuf = getPage(nextPageIdUpperLimit)
- logger.debug("Processing page:")
- pageBuf.forEach { logger.debug("${it.id} ${it.subject} ${it.amount}") }
+ logger.debug("pageBuf #$i follows. Request wants #$page:")
+ pageBuf.forEach { logger.debug("ID: ${it.id}, subject: ${it.subject}, amount: ${it.currency}:${it.amount}") }
if (pageBuf.none()) return@transaction
nextPageIdUpperLimit = pageBuf.last().id.value - 1
if (i == page) pageBuf.forEach {