gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libeufin] 02/02: refactoring


From: gnunet
Subject: [GNUnet-SVN] [libeufin] 02/02: refactoring
Date: Fri, 27 Sep 2019 19:47:11 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository libeufin.

commit a8bde648bb82fa3c00f3197eedde84cf54331185
Author: Florian Dold <address@hidden>
AuthorDate: Fri Sep 27 19:47:03 2019 +0200

    refactoring
---
 src/main/kotlin/Main.kt             | 73 ++++++++++++++++++-------------------
 src/main/kotlin/tech/libeufin/DB.kt |  1 -
 2 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt
index c36849d..8bc678e 100644
--- a/src/main/kotlin/Main.kt
+++ b/src/main/kotlin/Main.kt
@@ -33,8 +33,6 @@ import org.w3c.dom.Document
 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.*
 import org.jetbrains.exposed.sql.transactions.transaction
 import tech.libeufin.tech.libeufin.*
 import java.lang.NumberFormatException
@@ -63,22 +61,8 @@ fun main() {
             }
 
             post("/admin/customers") {
-
-                var returnId = 0
-                try {
-
-                    val body = call.receive<CustomerRequest>()
-                    logger.info(body.toString())
-
-                    transaction {
-                        val newBankCustomer = BankCustomers.insertAndGetId {
-                            it[name] = body.name
-                            it[ebicsSubscriber] = createSubscriber().id
-                        }
-
-                        returnId = newBankCustomer.value
-                    }
-
+                val body = try {
+                    call.receive<CustomerRequest>()
                 } catch (e: Exception) {
                     e.printStackTrace()
                     call.respond(
@@ -87,6 +71,26 @@ fun main() {
                     )
                     return@post
                 }
+                logger.info(body.toString())
+
+                val returnId = transaction {
+                    val myUserId = EbicsUser.new { }
+                    val myPartnerId = EbicsPartner.new { }
+                    val mySystemId = EbicsSystem.new { }
+                    val subscriber = EbicsSubscriber.new {
+                        userId = myUserId
+                        partnerId = myPartnerId
+                        systemId = mySystemId
+                        state = SubscriberStates.NEW
+                    }
+                    println("subscriber ID: ${subscriber.id.value}")
+                    val customer = BankCustomer.new {
+                        name = body.name
+                        ebicsSubscriber = subscriber
+                    }
+                    println("name: ${customer.name}")
+                    return@transaction customer.id.value
+                }
 
                 call.respond(
                     HttpStatusCode.OK,
@@ -98,32 +102,20 @@ fun main() {
 
             get("/admin/customers/{id}") {
 
-                var id = -1
-                var tmp: CustomerInfo? = null
-                var result: ResultRow? = null
-
-                try {
-                    id = call.parameters["id"]!!.toInt()
-                    logger.info("Querying ID: $id")
+                val id: Int = try {
+                    call.parameters["id"]!!.toInt()
                 } catch (e: NumberFormatException) {
                     call.respond(
                         HttpStatusCode.BadRequest,
                         SandboxError(e.message.toString())
                     )
+                    return@get
                 }
 
-                transaction {
-                    val singleton = BankCustomers.select { BankCustomers.id eq 
id }
-                    result = singleton.firstOrNull()
-
-                    if (null != result)
-                        tmp = CustomerInfo(
-                            result?.get(BankCustomers.name) as String,
-                            customerEbicsInfo = CustomerEbicsInfo(
-                                
result?.get(BankCustomers.ebicsSubscriber)?.value as Int
-                        )
-                    )
+                logger.info("Querying ID: $id")
 
+                val result = transaction {
+                    BankCustomer.findById(id)
                 }
 
                 if (null == result) {
@@ -134,9 +126,16 @@ fun main() {
                     return@get
                 }
 
+                val tmp = CustomerInfo(
+                    result.name,
+                    customerEbicsInfo = CustomerEbicsInfo(
+                        result.ebicsSubscriber.userId.id.value
+                    )
+                )
+
                 call.respond(
                     HttpStatusCode.OK,
-                    tmp as CustomerInfo
+                    tmp
                 )
             }
 
diff --git a/src/main/kotlin/tech/libeufin/DB.kt 
b/src/main/kotlin/tech/libeufin/DB.kt
index 2ed8931..70abf04 100644
--- a/src/main/kotlin/tech/libeufin/DB.kt
+++ b/src/main/kotlin/tech/libeufin/DB.kt
@@ -1,6 +1,5 @@
 package tech.libeufin.tech.libeufin
 
-import com.sun.org.apache.bcel.internal.generic.NEW
 import org.jetbrains.exposed.dao.*
 import org.jetbrains.exposed.sql.*
 import org.jetbrains.exposed.sql.transactions.transaction

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]