libeufin

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

commit d9c604ba4607a99ebe46dd60d7e11c373080a019
parent e3024eb76bc43feee3122a1ae95a5bfce2124183
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Thu, 26 Sep 2019 21:08:03 +0200

half-baking customerInfo request

Diffstat:
Msrc/main/kotlin/Main.kt | 39+++++++++++++++++++++++++++++++--------
Msrc/main/kotlin/tech/libeufin/DB.kt | 7+++++++
2 files changed, 38 insertions(+), 8 deletions(-)

diff --git 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 @@ -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: