commit 40584d155da002ca78073df6c7352f887ef198cf
parent 0a5fec853dac05f66dce1ea857ff1579fe0a935e
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 28 Nov 2019 19:07:40 +0100
introduce balances (database)
Diffstat:
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -97,17 +97,30 @@ fun Blob.toByteArray(): ByteArray {
object BankCustomersTable : IntIdTable() {
// Customer ID is the default 'id' field provided by the constructor.
val name = varchar("name", CUSTOMER_NAME_MAX_LENGTH).primaryKey()
- val ebicsSubscriber = reference("ebicsSubscriber", EbicsSubscribersTable)
+ val balance = reference("balance", BalanceTable)
}
class BankCustomerEntity(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<BankCustomerEntity>(BankCustomersTable)
-
var name by BankCustomersTable.name
- var ebicsSubscriber by EbicsSubscriberEntity referencedOn BankCustomersTable.ebicsSubscriber
+ val balance by BalanceTable referencedOn BankCustomersTable.balance
+}
+
+object BalanceTable : IntIdTable() {
+ // Customer ID is the default 'id' field provided by the constructor.
+ val value = int("value")
+ val fraction = int("fraction") // from 0 to 99
+}
+
+class BalanceEntity(id: EntityID<Int>) : IntEntity(id) {
+ companion object : IntEntityClass<BankCustomerEntity>(BankCustomersTable)
+
+ var balance by BalanceTable.balance
}
+
+
/**
* This table stores RSA public keys of subscribers.
*/
@@ -163,6 +176,7 @@ object EbicsSubscribersTable : IntIdTable() {
val nextOrderID = integer("nextOrderID")
val state = enumeration("state", SubscriberState::class)
+ val balance = reference("balance", BalanceTable)
}
class EbicsSubscriberEntity(id: EntityID<Int>) : IntEntity(id) {
@@ -179,6 +193,7 @@ class EbicsSubscriberEntity(id: EntityID<Int>) : IntEntity(id) {
var nextOrderID by EbicsSubscribersTable.nextOrderID
var state by EbicsSubscribersTable.state
+ var balance by BalanceTable referencedOn EbicsSubscribersTable.balance
}
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -110,13 +110,19 @@ fun main() {
signaturePrivateKey = SerialBlob(pairC.private.encoded)
}
- EbicsSubscriberEntity.new {
+ val subscriber = EbicsSubscriberEntity.new {
partnerId = "PARTNER1"
userId = "USER1"
systemId = null
state = SubscriberState.NEW
nextOrderID = 1
}
+
+ BankCustomerEntity.new {
+ name = "Mina"
+ balance = 0
+ ebicsSubscriber = subscriber
+ }
}
val server = embeddedServer(Netty, port = 5000) {