Adjusted to updated model that lists are now val MutableLists

This commit is contained in:
dankito 2024-09-16 23:33:56 +02:00
parent 96c8cf59cd
commit 4cd727b5c0
5 changed files with 21 additions and 21 deletions

View File

@ -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,

View File

@ -28,19 +28,19 @@ open class SqliteBankingRepository(
override fun getAllBanks(): List<BankAccessEntity> {
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<Long, List<BankAccountEntity>>, holdings: Map<Long, List<HoldingEntity>>): List<BankAccountEntity> {
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

View File

@ -20,10 +20,10 @@ class BankAccessEntity(
override val accounts: List<BankAccountEntity> = emptyList(),
selectedTanMethodIdentifier: String? = null,
override val tanMethods: List<TanMethodEntity> = listOf(),
override val tanMethods: MutableList<TanMethodEntity> = mutableListOf(),
selectedTanMediumIdentifier: String? = null,
tanMedia: List<TanMedium> = listOf(),
override val tanMedia: MutableList<TanMediumEntity> = 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,

View File

@ -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<AccountTransactionEntity> = mutableListOf(),
override val bookedTransactions: MutableList<AccountTransactionEntity> = mutableListOf(),
prebookedTransactions: MutableList<PrebookedAccountTransaction> = mutableListOf(),
override var holdings: List<HoldingEntity> = emptyList(),
override val holdings: MutableList<HoldingEntity> = mutableListOf(),
userSetDisplayName: String? = null,
displayIndex: Int = 0,
@ -48,7 +47,7 @@ class BankAccountEntity(
serverTransactionsRetentionDays, lastAccountUpdateTime, retrievedTransactionsFrom,
bookedTransactions as MutableList<AccountTransaction>, 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<AccountTransactionEntity> = bookedTransactions
fun addHoldings(holdings: List<HoldingEntity>) {
this.holdings.addAll(holdings)
}
}

View File

@ -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)