Adjusted to updated model that lists are now val MutableLists
This commit is contained in:
parent
96c8cf59cd
commit
4cd727b5c0
|
@ -61,7 +61,7 @@ class InMemoryBankingRepository(
|
||||||
nextId++,
|
nextId++,
|
||||||
bank.domesticBankCode, 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
|
// 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.bankingGroup, bank.serverAddress, bank.countryCode,
|
||||||
bank.userSetDisplayName, bank.displayIndex,
|
bank.userSetDisplayName, bank.displayIndex,
|
||||||
bank.iconUrl, bank.wrongCredentialsEntered,
|
bank.iconUrl, bank.wrongCredentialsEntered,
|
||||||
|
|
|
@ -28,19 +28,19 @@ open class SqliteBankingRepository(
|
||||||
|
|
||||||
override fun getAllBanks(): List<BankAccessEntity> {
|
override fun getAllBanks(): List<BankAccessEntity> {
|
||||||
val bankAccounts = getAllBankAccounts().groupBy { it.userId }
|
val bankAccounts = getAllBankAccounts().groupBy { it.userId }
|
||||||
val tanMethods = getAllTanMethods().groupBy { it.userId }
|
val tanMethods = getAllTanMethods().groupBy { it.userId }.mapValues { it.value.toMutableList() }
|
||||||
val tanMedia = getAllTanMedia().groupBy { it.userId }
|
val tanMedia = getAllTanMedia().groupBy { it.userId }.mapValues { it.value.toMutableList() }
|
||||||
val holdings = getAllHoldings().groupBy { it.bankAccountId }
|
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 ->
|
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)
|
bankingGroup?.let { BankingGroup.valueOf(it) }, serverAddress, "de", userSetDisplayName, displayIndex.toInt(), iconUrl, wrongCredentialsEntered)
|
||||||
}.executeAsList()
|
}.executeAsList()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun getAccountsOfBank(bankId: Long, bankAccounts: Map<Long, List<BankAccountEntity>>, holdings: Map<Long, List<HoldingEntity>>): List<BankAccountEntity> {
|
protected open fun getAccountsOfBank(bankId: Long, bankAccounts: Map<Long, List<BankAccountEntity>>, holdings: Map<Long, List<HoldingEntity>>): List<BankAccountEntity> {
|
||||||
return bankAccounts[bankId].orEmpty().onEach {
|
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),
|
mapToInt(serverTransactionsRetentionDays),
|
||||||
mapToInstant(lastAccountUpdateTime), mapToDate(retrievedTransactionsFrom),
|
mapToInstant(lastAccountUpdateTime), mapToDate(retrievedTransactionsFrom),
|
||||||
|
|
||||||
mutableListOf(), mutableListOf(), emptyList(),
|
mutableListOf(), mutableListOf(), mutableListOf(),
|
||||||
|
|
||||||
userSetDisplayName, mapToInt(displayIndex),
|
userSetDisplayName, mapToInt(displayIndex),
|
||||||
hideAccount, includeInAutomaticAccountsUpdate
|
hideAccount, includeInAutomaticAccountsUpdate
|
||||||
|
|
|
@ -20,10 +20,10 @@ class BankAccessEntity(
|
||||||
override val accounts: List<BankAccountEntity> = emptyList(),
|
override val accounts: List<BankAccountEntity> = emptyList(),
|
||||||
|
|
||||||
selectedTanMethodIdentifier: String? = null,
|
selectedTanMethodIdentifier: String? = null,
|
||||||
override val tanMethods: List<TanMethodEntity> = listOf(),
|
override val tanMethods: MutableList<TanMethodEntity> = mutableListOf(),
|
||||||
|
|
||||||
selectedTanMediumIdentifier: String? = null,
|
selectedTanMediumIdentifier: String? = null,
|
||||||
tanMedia: List<TanMedium> = listOf(),
|
override val tanMedia: MutableList<TanMediumEntity> = mutableListOf(),
|
||||||
|
|
||||||
bankingGroup: BankingGroup? = null,
|
bankingGroup: BankingGroup? = null,
|
||||||
serverAddress: String? = null,
|
serverAddress: String? = null,
|
||||||
|
@ -49,7 +49,7 @@ class BankAccessEntity(
|
||||||
id,
|
id,
|
||||||
bank.domesticBankCode, 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,
|
bankAccounts,
|
||||||
bank.selectedTanMethodIdentifier, tanMethods, bank.selectedTanMediumIdentifier, tanMedia,
|
bank.selectedTanMethodIdentifier, tanMethods.toMutableList(), bank.selectedTanMediumIdentifier, tanMedia.toMutableList(),
|
||||||
bank.bankingGroup, bank.serverAddress, bank.countryCode,
|
bank.bankingGroup, bank.serverAddress, bank.countryCode,
|
||||||
bank.userSetDisplayName, bank.displayIndex,
|
bank.userSetDisplayName, bank.displayIndex,
|
||||||
bank.iconUrl, bank.wrongCredentialsEntered,
|
bank.iconUrl, bank.wrongCredentialsEntered,
|
||||||
|
|
|
@ -3,7 +3,6 @@ package net.codinux.banking.dataaccess.entities
|
||||||
import kotlinx.datetime.Instant
|
import kotlinx.datetime.Instant
|
||||||
import kotlinx.datetime.LocalDate
|
import kotlinx.datetime.LocalDate
|
||||||
import net.codinux.banking.client.model.*
|
import net.codinux.banking.client.model.*
|
||||||
import net.codinux.banking.client.model.securitiesaccount.Holding
|
|
||||||
|
|
||||||
class BankAccountEntity(
|
class BankAccountEntity(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
|
@ -28,9 +27,9 @@ class BankAccountEntity(
|
||||||
lastAccountUpdateTime: Instant? = null,
|
lastAccountUpdateTime: Instant? = null,
|
||||||
retrievedTransactionsFrom: LocalDate? = null,
|
retrievedTransactionsFrom: LocalDate? = null,
|
||||||
|
|
||||||
bookedTransactions: MutableList<AccountTransactionEntity> = mutableListOf(),
|
override val bookedTransactions: MutableList<AccountTransactionEntity> = mutableListOf(),
|
||||||
prebookedTransactions: MutableList<PrebookedAccountTransaction> = mutableListOf(),
|
prebookedTransactions: MutableList<PrebookedAccountTransaction> = mutableListOf(),
|
||||||
override var holdings: List<HoldingEntity> = emptyList(),
|
override val holdings: MutableList<HoldingEntity> = mutableListOf(),
|
||||||
|
|
||||||
userSetDisplayName: String? = null,
|
userSetDisplayName: String? = null,
|
||||||
displayIndex: Int = 0,
|
displayIndex: Int = 0,
|
||||||
|
@ -48,7 +47,7 @@ class BankAccountEntity(
|
||||||
|
|
||||||
serverTransactionsRetentionDays, lastAccountUpdateTime, retrievedTransactionsFrom,
|
serverTransactionsRetentionDays, lastAccountUpdateTime, retrievedTransactionsFrom,
|
||||||
|
|
||||||
bookedTransactions as MutableList<AccountTransaction>, prebookedTransactions,
|
bookedTransactions, prebookedTransactions,
|
||||||
holdings,
|
holdings,
|
||||||
|
|
||||||
userSetDisplayName, displayIndex,
|
userSetDisplayName, displayIndex,
|
||||||
|
@ -68,12 +67,15 @@ class BankAccountEntity(
|
||||||
account.serverTransactionsRetentionDays,
|
account.serverTransactionsRetentionDays,
|
||||||
account.lastAccountUpdateTime, account.retrievedTransactionsFrom,
|
account.lastAccountUpdateTime, account.retrievedTransactionsFrom,
|
||||||
|
|
||||||
transactions.toMutableList(), mutableListOf(), holdings,
|
transactions.toMutableList(), mutableListOf(), holdings.toMutableList(),
|
||||||
|
|
||||||
account.userSetDisplayName, account.displayIndex,
|
account.userSetDisplayName, account.displayIndex,
|
||||||
account.hideAccount, account.includeInAutomaticAccountsUpdate
|
account.hideAccount, account.includeInAutomaticAccountsUpdate
|
||||||
)
|
)
|
||||||
|
|
||||||
val bookedTransactionsEntities: MutableList<AccountTransactionEntity> = bookedTransactions
|
|
||||||
|
fun addHoldings(holdings: List<HoldingEntity>) {
|
||||||
|
this.holdings.addAll(holdings)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -106,13 +106,13 @@ class BankingService(
|
||||||
|
|
||||||
val newBankEntity = bankingRepository.persistBank(newBank)
|
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()
|
val banks = uiState.banks.value.toMutableList()
|
||||||
banks.add(newBankEntity)
|
banks.add(newBankEntity)
|
||||||
uiState.banks.value = banks
|
uiState.banks.value = banks
|
||||||
|
|
||||||
updateTransactionsInUi(newBankEntity.accounts.flatMap { it.bookedTransactionsEntities })
|
updateTransactionsInUi(newBankEntity.accounts.flatMap { it.bookedTransactions })
|
||||||
updateHoldingsInUi(newBankEntity.accounts.flatMap { it.holdings }, emptyList())
|
updateHoldingsInUi(newBankEntity.accounts.flatMap { it.holdings }, emptyList())
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
log.error(e) { "Could not save bank ${response.bank}" }
|
log.error(e) { "Could not save bank ${response.bank}" }
|
||||||
|
@ -181,10 +181,8 @@ class BankingService(
|
||||||
bankingRepository.updateHoldings(updateHoldings(updatedExistingHoldings, updatedRetrievedHoldings))
|
bankingRepository.updateHoldings(updateHoldings(updatedExistingHoldings, updatedRetrievedHoldings))
|
||||||
bankingRepository.deleteHoldings(deletedHoldings)
|
bankingRepository.deleteHoldings(deletedHoldings)
|
||||||
|
|
||||||
account.holdings = account.holdings.toMutableList().apply {
|
account.holdings.removeAll(deletedHoldings)
|
||||||
addAll(persistedNewHoldings)
|
account.addHoldings(persistedNewHoldings)
|
||||||
removeAll(deletedHoldings)
|
|
||||||
}
|
|
||||||
|
|
||||||
updateHoldingsInUi(persistedNewHoldings, deletedHoldings)
|
updateHoldingsInUi(persistedNewHoldings, deletedHoldings)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue