[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: return balance as JSON
From: |
gnunet |
Subject: |
[libeufin] branch master updated: return balance as JSON |
Date: |
Mon, 02 Dec 2019 20:50:14 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository libeufin.
The following commit(s) were added to refs/heads/master by this push:
new 3a738ca return balance as JSON
3a738ca is described below
commit 3a738ca06c616e6bab151d816f5eb1f5bad432f9
Author: Marcello Stanisci <address@hidden>
AuthorDate: Mon Dec 2 20:50:07 2019 +0100
return balance as JSON
---
.../src/main/kotlin/tech/libeufin/sandbox/DB.kt | 3 ++-
.../src/main/kotlin/tech/libeufin/sandbox/Main.kt | 30 ++++++++++++++++------
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index 0301087..5d3251b 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -289,7 +289,8 @@ class EbicsUploadTransactionChunkEntity(id :
EntityID<String>): Entity<String>(i
fun dbCreateTables() {
- Database.connect("jdbc:sqlite:libeufin-sandbox.sqlite3", "org.sqlite.JDBC")
+ // Database.connect("jdbc:sqlite:libeufin-sandbox.sqlite3",
"org.sqlite.JDBC")
+ Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver =
"org.h2.Driver")
TransactionManager.manager.defaultIsolationLevel =
Connection.TRANSACTION_SERIALIZABLE
transaction {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index 6c0659c..b774b44 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -51,11 +51,23 @@ import javax.xml.bind.JAXBContext
val logger: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox")
-class CustomerNotFound(id: String?) : Exception("Customer {id} not found")
+class CustomerNotFound(id: String?) : Exception("Customer ${id} not found")
+class BadInputData(inputData: String?) : Exception("Customer provided invalid
input data: ${inputData}")
+
fun findCustomer(id: String?): BankCustomerEntity {
- if (id == null) throw Exception("Client gave null value as 'id'")
- return BankCustomerEntity.findById(id.toInt()) ?: throw
CustomerNotFound(id)
+
+ val idN = try {
+ id!!.toInt()
+ } catch (e: Exception) {
+ e.printStackTrace()
+ throw BadInputData(id)
+ }
+
+ return transaction {
+
+ BankCustomerEntity.findById(idN) ?: throw CustomerNotFound(id)
+ }
}
fun findEbicsSubscriber(partnerID: String, userID: String, systemID: String?):
EbicsSubscriberEntity? {
@@ -101,7 +113,6 @@ inline fun <reified T> Document.toObject(): T {
return m.unmarshal(this, T::class.java).value
}
-
fun main() {
dbCreateTables()
@@ -121,7 +132,7 @@ fun main() {
name = "Mina"
balance = BalanceEntity.new {
value = 0
- fraction = 0
+ fraction = 99
}
}
@@ -159,10 +170,13 @@ fun main() {
routing {
get("/{id}/balance") {
- val customer = findCustomer(call.parameters["id"])
+ val (name, value, fraction) = transaction {
+ val tmp = findCustomer(call.parameters["id"])
+ Triple(tmp.name, tmp.balance.value, tmp.balance.fraction)
+ }
call.respond(CustomerBalance(
- name = customer.name,
- balance =
"EUR:{customer.balance.value}.{customer.balance.fraction}"
+ name = name,
+ balance = "EUR:${value}.${fraction}"
))
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: return balance as JSON,
gnunet <=