commit 9aa0c1a031d4c72d045b553a215d776994a9b4ee
parent 17ab6d7a67f3b7e7c3ff97ac78cf3448bb7c20cc
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Fri, 6 Dec 2019 23:30:35 +0100
Sample data, plus balance construction.
Diffstat:
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -371,6 +371,7 @@ fun dbCreateTables() {
transaction {
SchemaUtils.createMissingTablesAndColumns(
+ BankTransactionsTable,
BankCustomersTable,
EbicsSubscribersTable,
EbicsHostsTable,
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -40,6 +40,7 @@ import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.transactions.transaction
+import org.joda.time.DateTime
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.w3c.dom.Document
@@ -118,6 +119,10 @@ inline fun <reified T> Document.toObject(): T {
return m.unmarshal(this, T::class.java).value
}
+fun sampleTransactions() {
+
+}
+
fun main() {
dbCreateTables()
@@ -138,7 +143,6 @@ fun main() {
name = "Mina"
}
-
EbicsSubscriberEntity.new {
partnerId = "PARTNER1"
userId = "USER1"
@@ -147,6 +151,17 @@ fun main() {
nextOrderID = 1
bankCustomer = customerEntity
}
+
+ for (i in 1..10) {
+ BankTransactionEntity.new {
+ counterpart = "IBAN"
+ amount = Amount(1)
+ subject = "transaction $i"
+ date = DateTime.now()
+ localCustomer = customerEntity
+ }
+
+ }
}
val server = embeddedServer(Netty, port = 5000) {
@@ -179,7 +194,14 @@ fun main() {
get("/{id}/balance") {
val (name, balance) = transaction {
val tmp: BankCustomerEntity = findCustomer(call.parameters["id"])
- Pair(tmp.name, 0) // fixme/todo!
+
+ var ret = Amount(0)
+ BankTransactionEntity.find {
+ BankTransactionsTable.localCustomer eq tmp.id
+ }.forEach {
+ ret += it.amount
+ }
+ Pair(tmp.name, ret)
}
call.respond(
@@ -188,6 +210,8 @@ fun main() {
balance = "EUR:${balance}"
)
)
+
+ return@get
}
get("/") {