From 729df3c1230b382bfeb26c8befce397cf1d29940 Mon Sep 17 00:00:00 2001 From: MS Date: Thu, 28 May 2020 17:21:52 +0200 Subject: TWG: finding the handler of outgoing history. --- nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt') diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt index 09dbc801..3dc91fe9 100644 --- a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt +++ b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt @@ -408,6 +408,43 @@ fun ingestTransactions() { } } +suspend fun historyOutgoing(call: ApplicationCall): Unit { + /* sanitize URL arguments */ + val subscriberId = authenticateRequest(call.request) + val delta: Int = expectInt(call.expectUrlParameter("delta")) + val start: Long = handleStartArgument(call.request.queryParameters["start"], delta) + val startCmpOp = getComparisonOperator(delta, start, TalerRequestedPayments) + /* retrieve database elements */ + val history = TalerOutgoingHistory() + transaction { + /** Retrieve all the outgoing payments from the _clean Taler outgoing table_ */ + val subscriberBankAccount = NexusBankAccountEntity.new { /* FIXME; exchange should communicate this value */ } + val reqPayments = TalerRequestedPaymentEntity.find { + TalerRequestedPayments.rawConfirmed.isNotNull() and startCmpOp + }.orderTaler(delta) + if (reqPayments.isNotEmpty()) { + reqPayments.subList(0, min(abs(delta), reqPayments.size)).forEach { + history.outgoing_transactions.add( + TalerOutgoingBankTransaction( + row_id = it.id.value, + amount = it.amount, + wtid = it.wtid, + date = GnunetTimestamp(it.rawConfirmed?.bookingDate?.div(1000) ?: throw NexusError( + HttpStatusCode.InternalServerError, "Null value met after check, VERY strange.")), + credit_account = it.creditAccount, + debit_account = buildPaytoUri(subscriberBankAccount.iban, subscriberBankAccount.bankCode), + exchange_base_url = "FIXME-to-request-along-subscriber-registration" + ) + ) + } + } + } + call.respond( + HttpStatusCode.OK, + TextContent(customConverter(history), ContentType.Application.Json) + ) +} + // /taler/history/incoming suspend fun historyIncoming(call: ApplicationCall): Unit { val exchangeUser = authenticateRequest(call.request) @@ -455,6 +492,7 @@ fun talerFacadeRoutes(route: Route) { return@post } route.get("/history/outgoing") { + historyOutgoing(call) return@get } route.get("/history/incoming") { -- cgit v1.2.3