[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 04/08: GET /user
From: |
gnunet |
Subject: |
[libeufin] 04/08: GET /user |
Date: |
Fri, 08 May 2020 20:04:48 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
commit cba69c62e6ec651e291b3f6a710ec0e136f78fc7
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri May 8 18:01:27 2020 +0200
GET /user
---
nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 2 +-
.../src/main/kotlin/tech/libeufin/nexus/Helpers.kt | 25 ++++++++++++++++++++++
nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 11 ++++++++++
.../kotlin/tech/libeufin/nexus/MainDeprecated.kt | 6 ------
4 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
index ba22010..ca5f4d2 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -164,7 +164,7 @@ class Pain001Entity(id: EntityID<Int>) : IntEntity(id) {
*/
object BankAccountsTable : IdTable<String>() {
override val id = varchar("id", ID_MAX_LENGTH).entityId().primaryKey()
- val accountHolder = text("accountHolder").nullable()
+ val accountHolder = text("accountHolder")
val iban = text("iban")
val bankCode = text("bankCode")
}
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
index 610db19..05ae29e 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -81,6 +81,31 @@ fun getBankAccountFromNexusUserId(id: String):
BankAccountEntity {
return map.bankAccount
}
+/**
+ * Given a nexus user id, returns the _list_ of bank accounts associated to it.
+ *
+ * @param id the subscriber id
+ * @return the (non-empty) list of bank accounts associated with this user.
+ */
+fun getBankAccountsFromNexusUserId(id: String): MutableList<BankAccountEntity>
{
+ logger.debug("Looking up bank account of user '$id'")
+ val ret = mutableListOf<BankAccountEntity>()
+ transaction {
+ BankAccountMapEntity.find {
+ BankAccountMapsTable.nexusUser eq id
+ }.forEach {
+ ret.add(it.bankAccount)
+ }
+ }
+ if (ret.isEmpty()) {
+ throw NexusError(
+ HttpStatusCode.NotFound,
+ "Such user '$id' does not have any bank account associated"
+ )
+ }
+ return ret
+}
+
fun getSubscriberDetailsInternal(subscriber: EbicsSubscriberEntity):
EbicsClientSubscriberDetails {
var bankAuthPubValue: RSAPublicKey? = null
if (subscriber.bankAuthenticationPublicKey != null) {
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 6ed2616..a632034 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -133,6 +133,17 @@ fun main() {
*/
get("/user") {
val userId =
authenticateRequest(call.request.headers["Authorization"])
+ val bankAccounts = BankAccounts()
+ getBankAccountsFromNexusUserId(userId).forEach {
+ bankAccounts.accounts.add(
+ BankAccount(
+ holder = it.accountHolder,
+ iban = it.iban,
+ bic = it.bankCode,
+ account = it.id.value
+ )
+ )
+ }
return@get
}
/**
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt
index eb9215a..547f0b2 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/MainDeprecated.kt
@@ -58,12 +58,6 @@ import java.util.zip.InflaterInputStream
import javax.crypto.EncryptedPrivateKeyInfo
import javax.sql.rowset.serial.SerialBlob
-
-data class NexusError(val statusCode: HttpStatusCode, val reason: String) :
Exception()
-
-val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus")
-
-
@ExperimentalIoApi
@KtorExperimentalAPI
fun main() {
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [libeufin] branch master updated (64b3929 -> f73bdad), gnunet, 2020/05/08
- [libeufin] 04/08: GET /user,
gnunet <=
- [libeufin] 01/08: Comments., gnunet, 2020/05/08
- [libeufin] 06/08: POST /users, gnunet, 2020/05/08
- [libeufin] 02/08: new API., gnunet, 2020/05/08
- [libeufin] 05/08: admin authentication helper, gnunet, 2020/05/08
- [libeufin] 03/08: fix compilation, gnunet, 2020/05/08
- [libeufin] 07/08: add GET /bank-accounts, fix GET /user., gnunet, 2020/05/08
- [libeufin] 08/08: POST preapred-payments/submit, gnunet, 2020/05/08