commit cba69c62e6ec651e291b3f6a710ec0e136f78fc7
parent 606a74d6ee3a811f2d38a995951ff4763fe608d6
Author: Marcello Stanisci <ms@taler.net>
Date: Fri, 8 May 2020 18:01:27 +0200
GET /user
Diffstat:
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
@@ -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
@@ -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
@@ -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
@@ -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() {