From 8613bdb06cd7cc3eb3d8e18a1155f872869b63cc Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 17 Aug 2024 22:14:06 +0200 Subject: [PATCH] Added GetAccountDataRequest so that user can specify credentials and GetAccountDataOptions in one object / request body --- .../net/codinux/banking/client/BankingClient.kt | 11 +++-------- .../client/BankingClientForCustomerBase.kt | 3 ++- .../banking/client/BlockingBankingClient.kt | 11 +++-------- .../BlockingBankingClientForCustomerBase.kt | 3 ++- .../banking/client/BankingClientExtensions.kt | 10 +++++----- .../banking/client/BankingClientExtensions.kt | 10 +++++----- .../client/model/options/GetAccountDataOptions.kt | 8 +++++++- .../client/model/request/GetAccountDataRequest.kt | 15 +++++++++++++++ .../client/fints4k/FinTs4kBankingClient.kt | 5 +++-- 9 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/request/GetAccountDataRequest.kt diff --git a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClient.kt b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClient.kt index 20bd14a7..1b304e9a 100644 --- a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClient.kt +++ b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClient.kt @@ -1,19 +1,14 @@ package net.codinux.banking.client -import net.codinux.banking.client.model.AccountCredentials -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.Response interface BankingClient { 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(credentials: AccountCredentials) = - getAccountDataAsync(credentials, GetAccountDataOptions()) - - suspend fun getAccountDataAsync(credentials: AccountCredentials, options: GetAccountDataOptions): Response + suspend fun getAccountDataAsync(request: GetAccountDataRequest): Response } \ No newline at end of file diff --git a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClientForCustomerBase.kt b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClientForCustomerBase.kt index 395cef53..9d447d9d 100644 --- a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClientForCustomerBase.kt +++ b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClientForCustomerBase.kt @@ -2,6 +2,7 @@ package net.codinux.banking.client import net.codinux.banking.client.model.AccountCredentials import net.codinux.banking.client.model.options.GetAccountDataOptions +import net.codinux.banking.client.model.request.GetAccountDataRequest abstract class BankingClientForCustomerBase( protected val credentials: AccountCredentials, @@ -9,6 +10,6 @@ abstract class BankingClientForCustomerBase( ) : BankingClientForCustomer { override suspend fun getAccountDataAsync(options: GetAccountDataOptions) = - client.getAccountDataAsync(credentials, options) + client.getAccountDataAsync(GetAccountDataRequest(credentials, options)) } \ No newline at end of file diff --git a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BlockingBankingClient.kt b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BlockingBankingClient.kt index 74c6e19b..a7b9725a 100644 --- a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BlockingBankingClient.kt +++ b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BlockingBankingClient.kt @@ -1,19 +1,14 @@ package net.codinux.banking.client -import net.codinux.banking.client.model.AccountCredentials -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.Response interface BlockingBankingClient { 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(credentials: AccountCredentials) = - getAccountData(credentials, GetAccountDataOptions()) - - fun getAccountData(credentials: AccountCredentials, options: GetAccountDataOptions): Response + fun getAccountData(request: GetAccountDataRequest): Response } \ No newline at end of file diff --git a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BlockingBankingClientForCustomerBase.kt b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BlockingBankingClientForCustomerBase.kt index 484fe19b..74b28879 100644 --- a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BlockingBankingClientForCustomerBase.kt +++ b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BlockingBankingClientForCustomerBase.kt @@ -2,6 +2,7 @@ package net.codinux.banking.client import net.codinux.banking.client.model.AccountCredentials import net.codinux.banking.client.model.options.GetAccountDataOptions +import net.codinux.banking.client.model.request.GetAccountDataRequest abstract class BlockingBankingClientForCustomerBase( protected val credentials: AccountCredentials, @@ -9,6 +10,6 @@ abstract class BlockingBankingClientForCustomerBase( ) : BlockingBankingClientForCustomer { override fun getAccountData(options: GetAccountDataOptions) = - client.getAccountData(credentials, options) + client.getAccountData(GetAccountDataRequest(credentials, options)) } \ No newline at end of file diff --git a/BankingClient/src/jvmMain/kotlin/net/codinux/banking/client/BankingClientExtensions.kt b/BankingClient/src/jvmMain/kotlin/net/codinux/banking/client/BankingClientExtensions.kt index 6e07146d..b8738b14 100644 --- a/BankingClient/src/jvmMain/kotlin/net/codinux/banking/client/BankingClientExtensions.kt +++ b/BankingClient/src/jvmMain/kotlin/net/codinux/banking/client/BankingClientExtensions.kt @@ -1,15 +1,15 @@ package net.codinux.banking.client 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.request.GetAccountDataRequest -fun BankingClient.getAccountData(credentials: AccountCredentials) = runBlocking { - this@getAccountData.getAccountDataAsync(credentials) +fun BankingClient.getAccountData(bankCode: String, loginName: String, password: String) = runBlocking { + this@getAccountData.getAccountDataAsync(bankCode, loginName, password) } -fun BankingClient.getAccountData(credentials: AccountCredentials, options: GetAccountDataOptions) = runBlocking { - this@getAccountData.getAccountDataAsync(credentials, options) +fun BankingClient.getAccountData(request: GetAccountDataRequest) = runBlocking { + this@getAccountData.getAccountDataAsync(request) } fun BankingClientForCustomer.getAccountData() = runBlocking { diff --git a/BankingClient/src/nativeMain/kotlin/net/codinux/banking/client/BankingClientExtensions.kt b/BankingClient/src/nativeMain/kotlin/net/codinux/banking/client/BankingClientExtensions.kt index 6e07146d..b8738b14 100644 --- a/BankingClient/src/nativeMain/kotlin/net/codinux/banking/client/BankingClientExtensions.kt +++ b/BankingClient/src/nativeMain/kotlin/net/codinux/banking/client/BankingClientExtensions.kt @@ -1,15 +1,15 @@ package net.codinux.banking.client 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.request.GetAccountDataRequest -fun BankingClient.getAccountData(credentials: AccountCredentials) = runBlocking { - this@getAccountData.getAccountDataAsync(credentials) +fun BankingClient.getAccountData(bankCode: String, loginName: String, password: String) = runBlocking { + this@getAccountData.getAccountDataAsync(bankCode, loginName, password) } -fun BankingClient.getAccountData(credentials: AccountCredentials, options: GetAccountDataOptions) = runBlocking { - this@getAccountData.getAccountDataAsync(credentials, options) +fun BankingClient.getAccountData(request: GetAccountDataRequest) = runBlocking { + this@getAccountData.getAccountDataAsync(request) } fun BankingClientForCustomer.getAccountData() = runBlocking { diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/options/GetAccountDataOptions.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/options/GetAccountDataOptions.kt index 02fdabcf..d68b4d80 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/options/GetAccountDataOptions.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/options/GetAccountDataOptions.kt @@ -1,11 +1,17 @@ package net.codinux.banking.client.model.options import kotlinx.datetime.LocalDate +import net.codinux.banking.client.model.config.NoArgConstructor +@NoArgConstructor open class GetAccountDataOptions( val retrieveBalance: Boolean = true, val retrieveTransactions: RetrieveTransactions = RetrieveTransactions.OfLast90Days, val retrieveTransactionsFrom: LocalDate? = null, val retrieveTransactionsTo: LocalDate? = null, val abortIfTanIsRequired: Boolean = false -) \ No newline at end of file +) { + override fun toString(): String { + return "retrieveBalance=$retrieveBalance, retrieveTransactions=$retrieveTransactions, abortIfTanIsRequired=$abortIfTanIsRequired" + } +} \ No newline at end of file diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/request/GetAccountDataRequest.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/request/GetAccountDataRequest.kt new file mode 100644 index 00000000..34e7905c --- /dev/null +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/request/GetAccountDataRequest.kt @@ -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" +} \ No newline at end of file diff --git a/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClient.kt b/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClient.kt index 27f9619f..7513c21f 100644 --- a/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClient.kt +++ b/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClient.kt @@ -3,6 +3,7 @@ package net.codinux.banking.client.fints4k import net.codinux.banking.client.BankingClient import net.codinux.banking.client.model.AccountCredentials 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.Response import net.dankito.banking.fints.FinTsClient @@ -17,8 +18,8 @@ open class FinTs4kBankingClient : BankingClient { }) - override suspend fun getAccountDataAsync(credentials: AccountCredentials, options: GetAccountDataOptions): Response { - val response = client.getAccountDataAsync(mapper.mapToGetAccountDataParameter(credentials, options)) + override suspend fun getAccountDataAsync(request: GetAccountDataRequest): Response { + val response = client.getAccountDataAsync(mapper.mapToGetAccountDataParameter(request, request.options ?: GetAccountDataOptions())) return mapper.map(response) }