commit e3024eb76bc43feee3122a1ae95a5bfce2124183
parent 9716c25bbfdf39205d0cd310bab5e1115faac8a8
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 26 Sep 2019 19:13:44 +0200
return ID upon successful user creation
Diffstat:
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt
@@ -35,6 +35,7 @@ import javax.xml.bind.JAXBElement
import io.ktor.features.*
import io.netty.handler.codec.http.HttpContent
import org.jetbrains.exposed.sql.insert
+import org.jetbrains.exposed.sql.insertAndGetId
import org.jetbrains.exposed.sql.transactions.transaction
import tech.libeufin.tech.libeufin.BankCustomers
import tech.libeufin.tech.libeufin.createSubscriber
@@ -64,18 +65,20 @@ fun main() {
}
post("/admin/customers") {
-
- // parse JSON
+ var returnId: Int = -1
try {
- val body = call.receive<Customer>()
+
+ val body = call.receive<CustomerRequest>()
logger.info(body.toString())
- logger.info("name:: ->> " + body.name)
+
transaction {
- BankCustomers.insert {
+ val newId = BankCustomers.insertAndGetId {
it[name] = body.name
it[ebicsSubscriber] = createSubscriber().id
}
+
+ returnId = newId.value
}
} catch (e: Exception) {
@@ -87,7 +90,11 @@ fun main() {
return@post
}
- call.respondText { "Successful user creation!\n" }
+ call.respond(
+ HttpStatusCode.OK,
+ CustomerResponse(id=returnId)
+ )
+
return@post
}
diff --git a/src/main/kotlin/tech/libeufin/JSON.kt b/src/main/kotlin/tech/libeufin/JSON.kt
@@ -11,10 +11,14 @@ data class SandboxError (
/**
* Request for POST /admin/customers
*/
-data class Customer (
+data class CustomerRequest (
val name: String
)
+data class CustomerResponse (
+ val id: Int
+)
+
/**
* Response for GET /admin/customers/:id
*/