commit 17e0d54abad446fa252542c1d319072e16719a88
parent 1affba91610fb88f8ccb782ec9cb430cba7f361f
Author: MS <ms@taler.net>
Date: Tue, 3 Oct 2023 12:09:32 +0200
GET /public-accounts
Diffstat:
3 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/BankMessages.kt b/bank/src/main/kotlin/tech/libeufin/bank/BankMessages.kt
@@ -655,7 +655,7 @@ data class TransferResponse(
*/
@Serializable
data class PublicAccountsResponse(
- val public_accounts: MutableList<PublicAccount>
+ val public_accounts: MutableList<PublicAccount> = mutableListOf()
)
@Serializable
data class PublicAccount(
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/CorebankApiHandlers.kt b/bank/src/main/kotlin/tech/libeufin/bank/CorebankApiHandlers.kt
@@ -222,7 +222,19 @@ fun Routing.accountsMgmtHandlers(db: Database, ctx: BankApplicationContext) {
}
get("/public-accounts") {
// no authentication here.
- // val publicAccounts = db.accountsGetPublic()
+ val publicAccounts = db.accountsGetPublic(ctx.currency)
+ if (publicAccounts.isEmpty()) {
+ call.respond(HttpStatusCode.NoContent)
+ return@get
+ }
+ call.respond(
+ PublicAccountsResponse().apply {
+ publicAccounts.forEach {
+ this.public_accounts.add(it)
+ }
+ }
+ )
+ return@get
}
get("/accounts") {
val c = call.authenticateBankRequest(db, TokenScope.readonly) ?: throw unauthorized()
diff --git a/bank/src/test/kotlin/LibeuFinApiTest.kt b/bank/src/test/kotlin/LibeuFinApiTest.kt
@@ -2,6 +2,7 @@ import io.ktor.client.plugins.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
+import io.ktor.http.content.*
import io.ktor.server.engine.*
import io.ktor.server.testing.*
import kotlinx.serialization.decodeFromString
@@ -230,6 +231,41 @@ class LibeuFinApiTest {
}
}
+ @Test
+ fun publicAccountsTest() {
+ val db = initDb()
+ val ctx = getTestContext()
+ testApplication {
+ application {
+ corebankWebApp(db, ctx)
+ }
+ client.get("/public-accounts").apply {
+ assert(this.status == HttpStatusCode.NoContent)
+ }
+ // Make one public account.
+ db.customerCreate(customerBar).apply {
+ assert(this != null)
+ assert(
+ db.bankAccountCreate(
+ BankAccount(
+ isPublic = true,
+ internalPaytoUri = "payto://iban/non-used",
+ lastNexusFetchRowId = 1L,
+ owningCustomerId = this!!,
+ hasDebt = false,
+ maxDebt = TalerAmount(10, 1, "KUDOS")
+ )
+ ) != null
+ )
+ }
+ client.get("/public-accounts").apply {
+ assert(this.status == HttpStatusCode.OK)
+ val obj = Json.decodeFromString<PublicAccountsResponse>(this.bodyAsText())
+ assert(obj.public_accounts.size == 1)
+ assert(obj.public_accounts[0].account_name == "bar")
+ }
+ }
+ }
// Creating token with "forever" duration.
@Test
fun tokenForeverTest() {