From 96c8cf59cdc6ccb073e8f7739e89cfc506021876 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 16 Sep 2024 23:21:20 +0200 Subject: [PATCH] Adjusted to updated model that bankCode has been renamed to domesticBankCode and countryCode got added --- .../banking/dataaccess/InMemoryBankingRepository.kt | 4 ++-- .../banking/dataaccess/SqliteBankingRepository.kt | 8 ++++---- .../banking/dataaccess/entities/BankAccessEntity.kt | 9 +++++---- .../net/codinux/banking/ui/dialogs/AddAccountDialog.kt | 2 +- .../kotlin/net/codinux/banking/ui/model/BankInfo.kt | 4 ++-- .../kotlin/net/codinux/banking/ui/service/BankFinder.kt | 4 ++-- .../net/codinux/banking/ui/service/BankingService.kt | 4 ++-- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt index 8881260..749c257 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt @@ -59,10 +59,10 @@ class InMemoryBankingRepository( private fun map(bank: BankAccess) = BankAccessEntity( nextId++, - bank.bankCode, bank.loginName, bank.password, bank.bankName, bank.bic, bank.customerName, bank.userId, + bank.domesticBankCode, bank.loginName, bank.password, bank.bankName, bank.bic, bank.customerName, bank.userId, // TODO: may fix someday and also add BankAccounts emptyList(), bank.selectedTanMethodIdentifier, emptyList(), bank.selectedTanMediumIdentifier, emptyList(), - bank.bankingGroup, bank.serverAddress, + bank.bankingGroup, bank.serverAddress, bank.countryCode, bank.userSetDisplayName, bank.displayIndex, bank.iconUrl, bank.wrongCredentialsEntered, ) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt index 0f1a005..976e556 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt @@ -32,9 +32,9 @@ open class SqliteBankingRepository( val tanMedia = getAllTanMedia().groupBy { it.userId } val holdings = getAllHoldings().groupBy { it.bankAccountId } - return bankQueries.selectAllBanks { id, bankCode, loginName, password, bankName, bic, customerName, userId, selectedTanMethodIdentifier, selectedTanMediumIdentifier, bankingGroup, serverAddress, userSetDisplayName, clientData, displayIndex, iconUrl, wrongCredentialsEntered -> - BankAccessEntity(id, bankCode, loginName, password, bankName, bic, customerName, userId, getAccountsOfBank(id, bankAccounts, holdings), selectedTanMethodIdentifier, tanMethods[id] ?: emptyList(), selectedTanMediumIdentifier, tanMedia[id] ?: emptyList(), - bankingGroup?.let { BankingGroup.valueOf(it) }, serverAddress, userSetDisplayName, displayIndex.toInt(), iconUrl, wrongCredentialsEntered) + return bankQueries.selectAllBanks { id, domesticBankCode, loginName, password, bankName, bic, customerName, userId, selectedTanMethodIdentifier, selectedTanMediumIdentifier, bankingGroup, serverAddress, userSetDisplayName, clientData, displayIndex, iconUrl, wrongCredentialsEntered -> + BankAccessEntity(id, domesticBankCode, loginName, password, bankName, bic, customerName, userId, getAccountsOfBank(id, bankAccounts, holdings), selectedTanMethodIdentifier, tanMethods[id] ?: emptyList(), selectedTanMediumIdentifier, tanMedia[id] ?: emptyList(), + bankingGroup?.let { BankingGroup.valueOf(it) }, serverAddress, "de", userSetDisplayName, displayIndex.toInt(), iconUrl, wrongCredentialsEntered) }.executeAsList() } @@ -46,7 +46,7 @@ open class SqliteBankingRepository( override suspend fun persistBank(bank: BankAccess): BankAccessEntity { return bankQueries.transactionWithResult { - bankQueries.insertBank(bank.bankCode, bank.loginName, bank.password, bank.bankName, bank.bic, + bankQueries.insertBank(bank.domesticBankCode, bank.loginName, bank.password, bank.bankName, bank.bic, bank.customerName, bank.userId, bank.selectedTanMethodIdentifier, bank.selectedTanMediumIdentifier, bank.bankingGroup?.name, bank.serverAddress, null, bank.userSetDisplayName, bank.displayIndex.toLong(), bank.iconUrl, bank.wrongCredentialsEntered ) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccessEntity.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccessEntity.kt index 5049de0..51a46f1 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccessEntity.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccessEntity.kt @@ -7,7 +7,7 @@ import net.codinux.banking.client.model.tan.TanMedium class BankAccessEntity( val id: Long, - bankCode: String, + domesticBankCode: String, loginName: String, password: String?, @@ -27,13 +27,14 @@ class BankAccessEntity( bankingGroup: BankingGroup? = null, serverAddress: String? = null, + countryCode: String = "de", userSetDisplayName: String? = null, displayIndex: Int = 0, iconUrl: String? = null, wrongCredentialsEntered: Boolean = false -) : BankAccess(bankCode, loginName, password, bankName, bic, customerName, userId, accounts, selectedTanMethodIdentifier, tanMethods, selectedTanMediumIdentifier, tanMedia, bankingGroup, serverAddress) { +) : BankAccess(domesticBankCode, loginName, password, bankName, bic, customerName, userId, accounts, selectedTanMethodIdentifier, tanMethods, selectedTanMediumIdentifier, tanMedia, bankingGroup, serverAddress, countryCode) { init { this.userSetDisplayName = userSetDisplayName @@ -46,10 +47,10 @@ class BankAccessEntity( constructor(id: Long, bank: BankAccess, bankAccounts: List, tanMethods: List, tanMedia: List) : this( id, - bank.bankCode, bank.loginName, bank.password, bank.bankName, bank.bic, bank.customerName, bank.userId, + bank.domesticBankCode, bank.loginName, bank.password, bank.bankName, bank.bic, bank.customerName, bank.userId, bankAccounts, bank.selectedTanMethodIdentifier, tanMethods, bank.selectedTanMediumIdentifier, tanMedia, - bank.bankingGroup, bank.serverAddress, + bank.bankingGroup, bank.serverAddress, bank.countryCode, bank.userSetDisplayName, bank.displayIndex, bank.iconUrl, bank.wrongCredentialsEntered, ) diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt index 542d0c2..a702c23 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/dialogs/AddAccountDialog.kt @@ -136,7 +136,7 @@ fun AddAccountDialog( } Row(Modifier.fillMaxWidth().padding(top = 6.dp)) { - Text(bank.bankCode, color = textColor) + Text(bank.domesticBankCode, color = textColor) Text("${bank.postalCode} ${bank.city}", Modifier.weight(1f).padding(start = 8.dp), color = if (supportsFinTs) Color.Gray else textColor) } diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/BankInfo.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/BankInfo.kt index 0748fd7..872abf3 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/BankInfo.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/model/BankInfo.kt @@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable @Serializable class BankInfo( val name: String, - val bankCode: String, + val domesticBankCode: String, val bic: String = "", val postalCode: String, val city: String, @@ -23,5 +23,5 @@ class BankInfo( get() = pinTanVersion == "FinTS V3.0" - override fun toString() = "$bankCode $name $city" + override fun toString() = "$domesticBankCode $name $city" } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankFinder.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankFinder.kt index 46903c7..31fb621 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankFinder.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankFinder.kt @@ -36,7 +36,7 @@ class BankFinder { return getBankList(maxItems) } - return getBankList().asSequence().filter { it.bankCode.startsWith(query) } + return getBankList().asSequence().filter { it.domesticBankCode.startsWith(query) } .max(maxItems) } @@ -69,7 +69,7 @@ class BankFinder { val bankCode = iban.substring(4) // first two letters are the country code, third and fourth char are the checksum, bank code starts at 5th char - val result = getBankList().asSequence().filter { it.bankCode.startsWith(bankCode) }.max(2) + val result = getBankList().asSequence().filter { it.domesticBankCode.startsWith(bankCode) }.max(2) return if (result.size > 1) { // non unique result, but should actually never happen for BICs null diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt index 8e751fc..29e41aa 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/BankingService.kt @@ -72,7 +72,7 @@ class BankingService( suspend fun addAccount(bank: BankInfo, loginName: String, password: String, retrieveAllTransactions: Boolean = false): Boolean { try { val retrieveTransactions = if (retrieveAllTransactions) RetrieveTransactions.All else RetrieveTransactions.OfLast90Days - val response = client.getAccountDataAsync(GetAccountDataRequest(bank.bankCode, loginName, password, GetAccountDataOptions(retrieveTransactions), mapBankInfo(bank))) + val response = client.getAccountDataAsync(GetAccountDataRequest(bank.domesticBankCode, loginName, password, GetAccountDataOptions(retrieveTransactions), mapBankInfo(bank))) if (response.type == ResponseType.Success && response.data != null) { handleSuccessfulGetAccountDataResponse(response.data!!) @@ -239,7 +239,7 @@ class BankingService( recipientName: String, recipientAccountIdentifier: String, amount: Amount, currency: String, paymentReference: String? = null, instantTransfer: Boolean = false, recipientBankIdentifier: String? = null): Boolean { val response = client.transferMoneyAsync(TransferMoneyRequestForUser( - bank.bankCode, bank.loginName, bank.password!!, + bank.domesticBankCode, bank.loginName, bank.password!!, BankAccountIdentifier(account.identifier, account.subAccountNumber, account.iban), // TODO: use BankingClient's one recipientName, recipientAccountIdentifier, recipientBankIdentifier, amount, "EUR",