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 749c257..e9121b3 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/InMemoryBankingRepository.kt @@ -61,7 +61,7 @@ class InMemoryBankingRepository( nextId++, 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(), + emptyList(), bank.selectedTanMethodIdentifier, mutableListOf(), bank.selectedTanMediumIdentifier, mutableListOf(), 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 976e556..9b8c22b 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/SqliteBankingRepository.kt @@ -28,19 +28,19 @@ open class SqliteBankingRepository( override fun getAllBanks(): List { val bankAccounts = getAllBankAccounts().groupBy { it.userId } - val tanMethods = getAllTanMethods().groupBy { it.userId } - val tanMedia = getAllTanMedia().groupBy { it.userId } + val tanMethods = getAllTanMethods().groupBy { it.userId }.mapValues { it.value.toMutableList() } + val tanMedia = getAllTanMedia().groupBy { it.userId }.mapValues { it.value.toMutableList() } val holdings = getAllHoldings().groupBy { it.bankAccountId } 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(), + BankAccessEntity(id, domesticBankCode, loginName, password, bankName, bic, customerName, userId, getAccountsOfBank(id, bankAccounts, holdings), selectedTanMethodIdentifier, tanMethods[id] ?: mutableListOf(), selectedTanMediumIdentifier, tanMedia[id] ?: mutableListOf(), bankingGroup?.let { BankingGroup.valueOf(it) }, serverAddress, "de", userSetDisplayName, displayIndex.toInt(), iconUrl, wrongCredentialsEntered) }.executeAsList() } protected open fun getAccountsOfBank(bankId: Long, bankAccounts: Map>, holdings: Map>): List { return bankAccounts[bankId].orEmpty().onEach { - it.holdings = holdings[it.id].orEmpty() + it.addHoldings(holdings[it.id].orEmpty()) } } @@ -79,7 +79,7 @@ open class SqliteBankingRepository( mapToInt(serverTransactionsRetentionDays), mapToInstant(lastAccountUpdateTime), mapToDate(retrievedTransactionsFrom), - mutableListOf(), mutableListOf(), emptyList(), + mutableListOf(), mutableListOf(), mutableListOf(), userSetDisplayName, mapToInt(displayIndex), hideAccount, includeInAutomaticAccountsUpdate 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 51a46f1..fcad5a6 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 @@ -20,10 +20,10 @@ class BankAccessEntity( override val accounts: List = emptyList(), selectedTanMethodIdentifier: String? = null, - override val tanMethods: List = listOf(), + override val tanMethods: MutableList = mutableListOf(), selectedTanMediumIdentifier: String? = null, - tanMedia: List = listOf(), + override val tanMedia: MutableList = mutableListOf(), bankingGroup: BankingGroup? = null, serverAddress: String? = null, @@ -49,7 +49,7 @@ class BankAccessEntity( id, bank.domesticBankCode, bank.loginName, bank.password, bank.bankName, bank.bic, bank.customerName, bank.userId, bankAccounts, - bank.selectedTanMethodIdentifier, tanMethods, bank.selectedTanMediumIdentifier, tanMedia, + bank.selectedTanMethodIdentifier, tanMethods.toMutableList(), bank.selectedTanMediumIdentifier, tanMedia.toMutableList(), 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/entities/BankAccountEntity.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccountEntity.kt index 3560dce..aa001e1 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccountEntity.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/dataaccess/entities/BankAccountEntity.kt @@ -3,7 +3,6 @@ package net.codinux.banking.dataaccess.entities import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate import net.codinux.banking.client.model.* -import net.codinux.banking.client.model.securitiesaccount.Holding class BankAccountEntity( val id: Long, @@ -28,9 +27,9 @@ class BankAccountEntity( lastAccountUpdateTime: Instant? = null, retrievedTransactionsFrom: LocalDate? = null, - bookedTransactions: MutableList = mutableListOf(), + override val bookedTransactions: MutableList = mutableListOf(), prebookedTransactions: MutableList = mutableListOf(), - override var holdings: List = emptyList(), + override val holdings: MutableList = mutableListOf(), userSetDisplayName: String? = null, displayIndex: Int = 0, @@ -48,7 +47,7 @@ class BankAccountEntity( serverTransactionsRetentionDays, lastAccountUpdateTime, retrievedTransactionsFrom, - bookedTransactions as MutableList, prebookedTransactions, + bookedTransactions, prebookedTransactions, holdings, userSetDisplayName, displayIndex, @@ -68,12 +67,15 @@ class BankAccountEntity( account.serverTransactionsRetentionDays, account.lastAccountUpdateTime, account.retrievedTransactionsFrom, - transactions.toMutableList(), mutableListOf(), holdings, + transactions.toMutableList(), mutableListOf(), holdings.toMutableList(), account.userSetDisplayName, account.displayIndex, account.hideAccount, account.includeInAutomaticAccountsUpdate ) - val bookedTransactionsEntities: MutableList = bookedTransactions + + fun addHoldings(holdings: List) { + this.holdings.addAll(holdings) + } } \ No newline at end of file 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 29e41aa..0667691 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 @@ -106,13 +106,13 @@ class BankingService( val newBankEntity = bankingRepository.persistBank(newBank) - log.info { "Saved bank $newBankEntity with ${newBankEntity.accounts.flatMap { it.bookedTransactionsEntities }.size} transactions" } + log.info { "Saved bank $newBankEntity with ${newBankEntity.accounts.flatMap { it.bookedTransactions }.size} transactions" } val banks = uiState.banks.value.toMutableList() banks.add(newBankEntity) uiState.banks.value = banks - updateTransactionsInUi(newBankEntity.accounts.flatMap { it.bookedTransactionsEntities }) + updateTransactionsInUi(newBankEntity.accounts.flatMap { it.bookedTransactions }) updateHoldingsInUi(newBankEntity.accounts.flatMap { it.holdings }, emptyList()) } catch (e: Throwable) { log.error(e) { "Could not save bank ${response.bank}" } @@ -181,10 +181,8 @@ class BankingService( bankingRepository.updateHoldings(updateHoldings(updatedExistingHoldings, updatedRetrievedHoldings)) bankingRepository.deleteHoldings(deletedHoldings) - account.holdings = account.holdings.toMutableList().apply { - addAll(persistedNewHoldings) - removeAll(deletedHoldings) - } + account.holdings.removeAll(deletedHoldings) + account.addHoldings(persistedNewHoldings) updateHoldingsInUi(persistedNewHoldings, deletedHoldings)