[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libeufin] branch master updated: half-baking customerInfo
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libeufin] branch master updated: half-baking customerInfo request |
Date: |
Thu, 26 Sep 2019 21:08:26 +0200 |
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 d9c604b half-baking customerInfo request
d9c604b is described below
commit d9c604ba4607a99ebe46dd60d7e11c373080a019
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Sep 26 21:08:03 2019 +0200
half-baking customerInfo request
---
src/main/kotlin/Main.kt | 38 +++++++++++++++++++++++++++++--------
src/main/kotlin/tech/libeufin/DB.kt | 7 +++++++
2 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt
index 6aa657a..7b98666 100644
--- a/src/main/kotlin/Main.kt
+++ b/src/main/kotlin/Main.kt
@@ -34,12 +34,16 @@ import tech.libeufin.messages.HEVResponseDataType
import javax.xml.bind.JAXBElement
import io.ktor.features.*
import io.netty.handler.codec.http.HttpContent
+import org.jetbrains.exposed.sql.Query
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.insertAndGetId
+import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
+import tech.libeufin.tech.libeufin.BankCustomer
import tech.libeufin.tech.libeufin.BankCustomers
import tech.libeufin.tech.libeufin.createSubscriber
import tech.libeufin.tech.libeufin.dbCreateTables
+import java.lang.NumberFormatException
import java.text.*
fun main() {
@@ -65,20 +69,20 @@ fun main() {
}
post("/admin/customers") {
- var returnId: Int = -1
+
+ var returnId = 0
try {
val body = call.receive<CustomerRequest>()
logger.info(body.toString())
-
transaction {
- val newId = BankCustomers.insertAndGetId {
+ val newBankCustomer = BankCustomers.insertAndGetId {
it[name] = body.name
it[ebicsSubscriber] = createSubscriber().id
}
- returnId = newId.value
+ returnId = newBankCustomer.value
}
} catch (e: Exception) {
@@ -92,15 +96,33 @@ fun main() {
call.respond(
HttpStatusCode.OK,
- CustomerResponse(id=returnId)
+ CustomerResponse(id = returnId)
)
return@post
}
- get("/admin/customers/:id") {
+ get("/admin/customers/{id}") {
- // query DB and return JSON object.
+ var id = -1
+ var result = -1
+
+ try {
+ id = call.parameters["id"]!!.toInt()
+ logger.info("Querying ID: $id")
+ } catch (e: NumberFormatException) {
+ call.respond(
+ HttpStatusCode.BadRequest,
+ SandboxError(e.message.toString())
+ )
+ }
+ transaction {
+ val result = BankCustomers.select{BankCustomers.id eq 1}
+ }
+ call.respond(
+ HttpStatusCode.OK,
+ CustomerInfo(customerEbicsInfo = CustomerEbicsInfo(0))
+ )
}
post("/ebicsweb") {
@@ -164,4 +186,4 @@ fun main() {
}
}
server.start(wait = true)
-}
+}
\ No newline at end of file
diff --git a/src/main/kotlin/tech/libeufin/DB.kt
b/src/main/kotlin/tech/libeufin/DB.kt
index f5f9448..2ed8931 100644
--- a/src/main/kotlin/tech/libeufin/DB.kt
+++ b/src/main/kotlin/tech/libeufin/DB.kt
@@ -74,6 +74,13 @@ object BankCustomers: IntIdTable() {
val ebicsSubscriber = reference("ebicsSubscriber", EbicsUsers)
}
+class BankCustomer(id: EntityID<Int>) : IntEntity(id) {
+ companion object : IntEntityClass<BankCustomer>(BankCustomers)
+
+ var name by BankCustomers.name
+ var ebicsSubscriber by EbicsSubscriber referencedOn
BankCustomers.ebicsSubscriber
+}
+
/**
* The following tables define IDs that make a EBCIS
* 'subscriber' exist. Each EBICS subscriber is the tuple:
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [libeufin] branch master updated: half-baking customerInfo request,
gnunet <=