Added GetAccountDataRequest so that user can specify credentials and GetAccountDataOptions in one object / request body

This commit is contained in:
dankito 2024-08-17 22:14:06 +02:00
parent 7706ab5c99
commit 8613bdb06c
9 changed files with 45 additions and 31 deletions

View File

@ -1,19 +1,14 @@
package net.codinux.banking.client package net.codinux.banking.client
import net.codinux.banking.client.model.AccountCredentials import net.codinux.banking.client.model.request.GetAccountDataRequest
import net.codinux.banking.client.model.options.GetAccountDataOptions
import net.codinux.banking.client.model.response.GetAccountDataResponse import net.codinux.banking.client.model.response.GetAccountDataResponse
import net.codinux.banking.client.model.response.Response import net.codinux.banking.client.model.response.Response
interface BankingClient { interface BankingClient {
suspend fun getAccountDataAsync(bankCode: String, loginName: String, password: String) = suspend fun getAccountDataAsync(bankCode: String, loginName: String, password: String) =
getAccountDataAsync(AccountCredentials(bankCode, loginName, password)) getAccountDataAsync(GetAccountDataRequest(bankCode, loginName, password))
// for languages not supporting default parameters (Java, Swift, JS, ...) suspend fun getAccountDataAsync(request: GetAccountDataRequest): Response<GetAccountDataResponse>
suspend fun getAccountDataAsync(credentials: AccountCredentials) =
getAccountDataAsync(credentials, GetAccountDataOptions())
suspend fun getAccountDataAsync(credentials: AccountCredentials, options: GetAccountDataOptions): Response<GetAccountDataResponse>
} }

View File

@ -2,6 +2,7 @@ package net.codinux.banking.client
import net.codinux.banking.client.model.AccountCredentials import net.codinux.banking.client.model.AccountCredentials
import net.codinux.banking.client.model.options.GetAccountDataOptions import net.codinux.banking.client.model.options.GetAccountDataOptions
import net.codinux.banking.client.model.request.GetAccountDataRequest
abstract class BankingClientForCustomerBase( abstract class BankingClientForCustomerBase(
protected val credentials: AccountCredentials, protected val credentials: AccountCredentials,
@ -9,6 +10,6 @@ abstract class BankingClientForCustomerBase(
) : BankingClientForCustomer { ) : BankingClientForCustomer {
override suspend fun getAccountDataAsync(options: GetAccountDataOptions) = override suspend fun getAccountDataAsync(options: GetAccountDataOptions) =
client.getAccountDataAsync(credentials, options) client.getAccountDataAsync(GetAccountDataRequest(credentials, options))
} }

View File

@ -1,19 +1,14 @@
package net.codinux.banking.client package net.codinux.banking.client
import net.codinux.banking.client.model.AccountCredentials import net.codinux.banking.client.model.request.GetAccountDataRequest
import net.codinux.banking.client.model.options.GetAccountDataOptions
import net.codinux.banking.client.model.response.GetAccountDataResponse import net.codinux.banking.client.model.response.GetAccountDataResponse
import net.codinux.banking.client.model.response.Response import net.codinux.banking.client.model.response.Response
interface BlockingBankingClient { interface BlockingBankingClient {
suspend fun getAccountData(bankCode: String, loginName: String, password: String) = suspend fun getAccountData(bankCode: String, loginName: String, password: String) =
getAccountData(AccountCredentials(bankCode, loginName, password)) getAccountData(GetAccountDataRequest(bankCode, loginName, password))
// for languages not supporting default parameters (Java, Swift, JS, ...) fun getAccountData(request: GetAccountDataRequest): Response<GetAccountDataResponse>
fun getAccountData(credentials: AccountCredentials) =
getAccountData(credentials, GetAccountDataOptions())
fun getAccountData(credentials: AccountCredentials, options: GetAccountDataOptions): Response<GetAccountDataResponse>
} }

View File

@ -2,6 +2,7 @@ package net.codinux.banking.client
import net.codinux.banking.client.model.AccountCredentials import net.codinux.banking.client.model.AccountCredentials
import net.codinux.banking.client.model.options.GetAccountDataOptions import net.codinux.banking.client.model.options.GetAccountDataOptions
import net.codinux.banking.client.model.request.GetAccountDataRequest
abstract class BlockingBankingClientForCustomerBase( abstract class BlockingBankingClientForCustomerBase(
protected val credentials: AccountCredentials, protected val credentials: AccountCredentials,
@ -9,6 +10,6 @@ abstract class BlockingBankingClientForCustomerBase(
) : BlockingBankingClientForCustomer { ) : BlockingBankingClientForCustomer {
override fun getAccountData(options: GetAccountDataOptions) = override fun getAccountData(options: GetAccountDataOptions) =
client.getAccountData(credentials, options) client.getAccountData(GetAccountDataRequest(credentials, options))
} }

View File

@ -1,15 +1,15 @@
package net.codinux.banking.client package net.codinux.banking.client
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import net.codinux.banking.client.model.AccountCredentials
import net.codinux.banking.client.model.options.GetAccountDataOptions import net.codinux.banking.client.model.options.GetAccountDataOptions
import net.codinux.banking.client.model.request.GetAccountDataRequest
fun BankingClient.getAccountData(credentials: AccountCredentials) = runBlocking { fun BankingClient.getAccountData(bankCode: String, loginName: String, password: String) = runBlocking {
this@getAccountData.getAccountDataAsync(credentials) this@getAccountData.getAccountDataAsync(bankCode, loginName, password)
} }
fun BankingClient.getAccountData(credentials: AccountCredentials, options: GetAccountDataOptions) = runBlocking { fun BankingClient.getAccountData(request: GetAccountDataRequest) = runBlocking {
this@getAccountData.getAccountDataAsync(credentials, options) this@getAccountData.getAccountDataAsync(request)
} }
fun BankingClientForCustomer.getAccountData() = runBlocking { fun BankingClientForCustomer.getAccountData() = runBlocking {

View File

@ -1,15 +1,15 @@
package net.codinux.banking.client package net.codinux.banking.client
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import net.codinux.banking.client.model.AccountCredentials
import net.codinux.banking.client.model.options.GetAccountDataOptions import net.codinux.banking.client.model.options.GetAccountDataOptions
import net.codinux.banking.client.model.request.GetAccountDataRequest
fun BankingClient.getAccountData(credentials: AccountCredentials) = runBlocking { fun BankingClient.getAccountData(bankCode: String, loginName: String, password: String) = runBlocking {
this@getAccountData.getAccountDataAsync(credentials) this@getAccountData.getAccountDataAsync(bankCode, loginName, password)
} }
fun BankingClient.getAccountData(credentials: AccountCredentials, options: GetAccountDataOptions) = runBlocking { fun BankingClient.getAccountData(request: GetAccountDataRequest) = runBlocking {
this@getAccountData.getAccountDataAsync(credentials, options) this@getAccountData.getAccountDataAsync(request)
} }
fun BankingClientForCustomer.getAccountData() = runBlocking { fun BankingClientForCustomer.getAccountData() = runBlocking {

View File

@ -1,11 +1,17 @@
package net.codinux.banking.client.model.options package net.codinux.banking.client.model.options
import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalDate
import net.codinux.banking.client.model.config.NoArgConstructor
@NoArgConstructor
open class GetAccountDataOptions( open class GetAccountDataOptions(
val retrieveBalance: Boolean = true, val retrieveBalance: Boolean = true,
val retrieveTransactions: RetrieveTransactions = RetrieveTransactions.OfLast90Days, val retrieveTransactions: RetrieveTransactions = RetrieveTransactions.OfLast90Days,
val retrieveTransactionsFrom: LocalDate? = null, val retrieveTransactionsFrom: LocalDate? = null,
val retrieveTransactionsTo: LocalDate? = null, val retrieveTransactionsTo: LocalDate? = null,
val abortIfTanIsRequired: Boolean = false val abortIfTanIsRequired: Boolean = false
) ) {
override fun toString(): String {
return "retrieveBalance=$retrieveBalance, retrieveTransactions=$retrieveTransactions, abortIfTanIsRequired=$abortIfTanIsRequired"
}
}

View File

@ -0,0 +1,15 @@
package net.codinux.banking.client.model.request
import net.codinux.banking.client.model.AccountCredentials
import net.codinux.banking.client.model.config.NoArgConstructor
import net.codinux.banking.client.model.options.GetAccountDataOptions
@NoArgConstructor
open class GetAccountDataRequest(bankCode: String, loginName: String, password: String, val options: GetAccountDataOptions? = null)
: AccountCredentials(bankCode, loginName, password) {
constructor(credentials: AccountCredentials, options: GetAccountDataOptions? = null)
: this(credentials.bankCode, credentials.loginName, credentials.loginName, options)
override fun toString() = "${super.toString()}: $options"
}

View File

@ -3,6 +3,7 @@ package net.codinux.banking.client.fints4k
import net.codinux.banking.client.BankingClient import net.codinux.banking.client.BankingClient
import net.codinux.banking.client.model.AccountCredentials import net.codinux.banking.client.model.AccountCredentials
import net.codinux.banking.client.model.options.GetAccountDataOptions import net.codinux.banking.client.model.options.GetAccountDataOptions
import net.codinux.banking.client.model.request.GetAccountDataRequest
import net.codinux.banking.client.model.response.GetAccountDataResponse import net.codinux.banking.client.model.response.GetAccountDataResponse
import net.codinux.banking.client.model.response.Response import net.codinux.banking.client.model.response.Response
import net.dankito.banking.fints.FinTsClient import net.dankito.banking.fints.FinTsClient
@ -17,8 +18,8 @@ open class FinTs4kBankingClient : BankingClient {
}) })
override suspend fun getAccountDataAsync(credentials: AccountCredentials, options: GetAccountDataOptions): Response<GetAccountDataResponse> { override suspend fun getAccountDataAsync(request: GetAccountDataRequest): Response<GetAccountDataResponse> {
val response = client.getAccountDataAsync(mapper.mapToGetAccountDataParameter(credentials, options)) val response = client.getAccountDataAsync(mapper.mapToGetAccountDataParameter(request, request.options ?: GetAccountDataOptions()))
return mapper.map(response) return mapper.map(response)
} }