libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit bcf02d090c17ad1f7879893631d0f890ac4d28df
parent 58308f3a8e61aa9530368cfdb9be0a69825116c2
Author: tanhengyeow <E0032242@u.nus.edu>
Date:   Fri, 21 Aug 2020 14:33:09 +0800

Draft for /admin/statements and /admin/reports

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt | 26+++++++++++++++++++++++++-
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt @@ -50,7 +50,6 @@ data class PaymentsResponse( val payments: MutableList<RawPayment> = mutableListOf() ) - /** * Used to create AND show one Ebics subscriber in the system. */ @@ -72,3 +71,28 @@ data class BankAccountRequest( val name: String, val label: String ) + +data class DateRange( + val startDate: Long, + val endDate: Long +) + +data class BankAccountStatements( + var bankAccountStatements: MutableList<BankAccountStatement> = mutableListOf() +) + +data class BankAccountReports( + var bankAccountReports: MutableList<BankAccountReport> = mutableListOf() +) + +data class BankAccountStatement( + var statementId: String, + var creationTime: Long, + var message: MutableList<String> = mutableListOf() +) + +data class BankAccountReport( + var reportId: String, + var creationTime: Long, + val message: String +) diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -75,6 +75,7 @@ import tech.libeufin.sandbox.BankAccountTransactionsTable.debitorName import tech.libeufin.util.* import tech.libeufin.util.ebics_h004.EbicsResponse import tech.libeufin.util.ebics_h004.EbicsTypes +import java.util.UUID class CustomerNotFound(id: String?) : Exception("Customer ${id} not found") class BadInputData(inputData: String?) : Exception("Customer provided invalid input data: ${inputData}") @@ -382,6 +383,56 @@ fun serverMain(dbName: String) { post("/ebicsweb") { call.ebicsweb() } + /** + * Shows all bank account statements. + */ + get("/admin/statements") { + var ret = BankAccountStatement() + ret.creationTime = Instant.now().toEpochMilli() + ret.statementId = "C52-" + Instant.now().toEpochMilli().toHttpDateString() + "-" + UUID.randomUUID().toString() + ret.message = mutableListOf<String>() + transaction { + BankAccountTransactionsTable.selectAll().forEach { + ret.message.add( + constructXml(indent = true) { + root("Document") { + attribute("xmlns", "urn:iso:std:iso:20022:tech:xsd:camt.053.001.02") + attribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance") + attribute( + "xsi:schemaLocation", + "urn:iso:std:iso:20022:tech:xsd:camt.053.001.02 camt.053.001.02.xsd" + ) + element("Ntry") { + element("Amt") { + attribute("Ccy", it.currency) + text(it.amount) + } + } + } + } + ) + } + } + transaction { + BankAccountStatementsTable.insert { + it[statementId] = ret.statementId + it[creationTime] = ret.creationTime + it[xmlMessage] = ret.message.toString() + } + } + call.respond(ret) + return@get + } + /** + * Shows all bank account reports. + */ + get("/admin/reports") { + val body = call.receive<DateRange>() + var ret = BankAccountReport() + + call.respond(ret) + return@get + } } } LOGGER.info("Up and running")