gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libeufin] branch master updated: respond JSON error object


From: gnunet
Subject: [GNUnet-SVN] [libeufin] branch master updated: respond JSON error object
Date: Thu, 26 Sep 2019 16:27:55 +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 9677d86  respond JSON error object
9677d86 is described below

commit 9677d8671fd8fcc07f64721223ba22627350ad7c
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Sep 26 16:27:24 2019 +0200

    respond JSON error object
---
 build.gradle                                       |  2 +
 src/main/kotlin/Main.kt                            | 50 ++++++++++++++++++++--
 src/main/kotlin/tech/libeufin/DB.kt                |  7 ++-
 .../tech/libeufin/{messages => }/HEVResponse.kt    |  5 ++-
 src/main/kotlin/tech/libeufin/JSON.kt              | 27 ++++++++++++
 .../libeufin/{messages => }/ProtocolAndVersion.kt  |  2 +-
 6 files changed, 84 insertions(+), 9 deletions(-)

diff --git a/build.gradle b/build.gradle
index 0f632eb..18035e7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -15,6 +15,8 @@ repositories {
 
 dependencies {
     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
+    implementation "io.ktor:ktor-gson:1.1.5"
+    // compile group: 'io.ktor', name: 'ktor-gson', version: '0.9.0'
     compile "org.jetbrains.exposed:exposed:0.17.3"
     compile "io.ktor:ktor-server-netty:1.2.4"
     compile "ch.qos.logback:logback-classic:1.2.3"
diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt
index 90f0282..becbba8 100644
--- a/src/main/kotlin/Main.kt
+++ b/src/main/kotlin/Main.kt
@@ -19,18 +19,22 @@
 
 package tech.libeufin
 
+import io.ktor.gson.*
 import io.ktor.application.*
+import io.ktor.features.CallLogging
 import io.ktor.http.*
+import io.ktor.request.receive
 import io.ktor.request.receiveText
 import io.ktor.response.*
 import io.ktor.routing.*
 import io.ktor.server.engine.*
 import io.ktor.server.netty.*
 import org.w3c.dom.Document
-import tech.libeufin.messages.HEVResponse
 import tech.libeufin.messages.HEVResponseDataType
-import tech.libeufin.messages.ProtocolAndVersion
 import javax.xml.bind.JAXBElement
+import io.ktor.features.*
+import io.netty.handler.codec.http.HttpContent
+import java.text.*
 
 enum class Foo {BAR, BAZ}
 
@@ -40,13 +44,53 @@ fun main() {
     var logger = getLogger()
 
     val server = embeddedServer(Netty, port = 5000) {
+
+        install(CallLogging)
+        install(ContentNegotiation){
+            gson {
+                setDateFormat(DateFormat.LONG)
+                setPrettyPrinting()
+            }
+
+        }
+
         routing {
             get("/") {
                 logger.debug("GET: not implemented")
                 call.respondText("Hello LibEuFin!", ContentType.Text.Plain)
                 return@get
             }
-            post("/") {
+
+            post("/admin/customers") {
+
+                // parse JSON
+                try {
+                    val body = call.receive<Customer>()
+                    logger.info(body.toString())
+
+                } catch (e: Exception) {
+                    e.printStackTrace()
+                    // return error, FIXME: distinguish between server and 
client error!
+                    call.respond(
+                        HttpStatusCode.BadRequest,
+                        SandboxError(e.message.toString())
+                    )
+                    return@post
+                }
+
+
+
+                // create table entries: customer + user + partner + system.
+
+                // return response
+            }
+
+            get("/admin/customers/:id") {
+
+                // query DB and return JSON object.
+            }
+
+            post("/ebicsweb") {
                 val body: String = call.receiveText()
                 logger.debug("Body: $body")
 
diff --git a/src/main/kotlin/tech/libeufin/DB.kt 
b/src/main/kotlin/tech/libeufin/DB.kt
index 1bba1d2..6495487 100644
--- a/src/main/kotlin/tech/libeufin/DB.kt
+++ b/src/main/kotlin/tech/libeufin/DB.kt
@@ -4,7 +4,7 @@ import org.jetbrains.exposed.dao.IntIdTable
 import org.jetbrains.exposed.sql.*
 import org.jetbrains.exposed.sql.transactions.transaction
 
-const val CUSTOMER_ID_MAX_LENGTH = 20
+const val CUSTOMER_NAME_MAX_LENGTH = 20
 const val SUBSCRIBER_ID_MAX_LENGTH = 10
 const val PUBLIC_KEY_MAX_LENGTH = 256 // FIXME review this value!
 const val PRIV_KEY_MAX_LENGTH = 512 // FIXME review this value!
@@ -67,9 +67,8 @@ enum class KeyStates {
  * its customers.
  */
 object Customer: IntIdTable() {
-    val customerId: Column<String> = varchar(
-        "customerId",
-        CUSTOMER_ID_MAX_LENGTH).primaryKey()
+    // Customer ID is the default 'id' field provided by the constructor.
+    val name = varchar("name", CUSTOMER_NAME_MAX_LENGTH)
     val ebicsUserId = reference("ebicsUserId", EbicsUsers)
 }
 
diff --git a/src/main/kotlin/tech/libeufin/messages/HEVResponse.kt 
b/src/main/kotlin/tech/libeufin/HEVResponse.kt
similarity index 84%
rename from src/main/kotlin/tech/libeufin/messages/HEVResponse.kt
rename to src/main/kotlin/tech/libeufin/HEVResponse.kt
index c3afc06..97370d3 100644
--- a/src/main/kotlin/tech/libeufin/messages/HEVResponse.kt
+++ b/src/main/kotlin/tech/libeufin/HEVResponse.kt
@@ -1,5 +1,8 @@
-package tech.libeufin.messages
+package tech.libeufin
 
+import tech.libeufin.messages.HEVResponseDataType
+import tech.libeufin.messages.ObjectFactory
+import tech.libeufin.messages.SystemReturnCodeType
 import javax.xml.bind.JAXBElement
 
 
diff --git a/src/main/kotlin/tech/libeufin/JSON.kt 
b/src/main/kotlin/tech/libeufin/JSON.kt
new file mode 100644
index 0000000..d2b669f
--- /dev/null
+++ b/src/main/kotlin/tech/libeufin/JSON.kt
@@ -0,0 +1,27 @@
+package tech.libeufin
+
+/**
+ * Error message.
+ */
+data class SandboxError (
+    val message: String
+)
+
+
+/**
+ * Request for POST /admin/customers
+ */
+data class Customer (
+    val name: String
+)
+
+/**
+ * Response for GET /admin/customers/:id
+ */
+data class CustomerInfo (
+    val customerEbicsInfo: CustomerEbicsInfo
+)
+
+data class CustomerEbicsInfo (
+    val userId: Int
+)
\ No newline at end of file
diff --git a/src/main/kotlin/tech/libeufin/messages/ProtocolAndVersion.kt 
b/src/main/kotlin/tech/libeufin/ProtocolAndVersion.kt
similarity index 78%
rename from src/main/kotlin/tech/libeufin/messages/ProtocolAndVersion.kt
rename to src/main/kotlin/tech/libeufin/ProtocolAndVersion.kt
index 7db63ce..54bd465 100644
--- a/src/main/kotlin/tech/libeufin/messages/ProtocolAndVersion.kt
+++ b/src/main/kotlin/tech/libeufin/ProtocolAndVersion.kt
@@ -1,4 +1,4 @@
-package tech.libeufin.messages
+package tech.libeufin
 
 class ProtocolAndVersion(protocol: String, version: String) {
     val protocol = protocol

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



reply via email to

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