Saving clientData in db
This commit is contained in:
parent
e0e150e53a
commit
04fa2dcbb4
|
@ -31,6 +31,8 @@ interface BankingRepository {
|
||||||
|
|
||||||
suspend fun updateBank(bank: BankAccessEntity, loginName: String, password: String, bankName: String?)
|
suspend fun updateBank(bank: BankAccessEntity, loginName: String, password: String, bankName: String?)
|
||||||
|
|
||||||
|
suspend fun updateBank(bank: BankAccessEntity, clientData: String?)
|
||||||
|
|
||||||
suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean)
|
suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean)
|
||||||
|
|
||||||
suspend fun updateAccount(account: BankAccountEntity, balance: Amount, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?)
|
suspend fun updateAccount(account: BankAccountEntity, balance: Amount, lastAccountUpdateTime: Instant, retrievedTransactionsFrom: LocalDate?)
|
||||||
|
|
|
@ -55,6 +55,10 @@ class InMemoryBankingRepository(
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun updateBank(bank: BankAccessEntity, clientData: String?) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) {
|
override suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ open class SqliteBankingRepository : BankingRepository {
|
||||||
|
|
||||||
return bankQueries.getAllBanks { id, domesticBankCode, loginName, password, bankName, bic, customerName, userId, selectedTanMethodIdentifier, selectedTanMediumIdentifier, bankingGroup, serverAddress, countryCode, clientData, userSetDisplayName, displayIndex, iconUrl, wrongCredentialsEntered ->
|
return bankQueries.getAllBanks { id, domesticBankCode, loginName, password, bankName, bic, customerName, userId, selectedTanMethodIdentifier, selectedTanMediumIdentifier, bankingGroup, serverAddress, countryCode, clientData, userSetDisplayName, displayIndex, iconUrl, wrongCredentialsEntered ->
|
||||||
BankAccessEntity(id, domesticBankCode, loginName, password, bankName, bic, customerName, userId, getAccountsOfBank(id, bankAccounts, holdings), selectedTanMethodIdentifier, tanMethods[id] ?: mutableListOf(), selectedTanMediumIdentifier, tanMedia[id] ?: mutableListOf(),
|
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, countryCode, userSetDisplayName, displayIndex.toInt(), iconUrl, wrongCredentialsEntered)
|
bankingGroup?.let { BankingGroup.valueOf(it) }, serverAddress, countryCode, userSetDisplayName, displayIndex.toInt(), iconUrl, wrongCredentialsEntered, clientData)
|
||||||
}.executeAsList()
|
}.executeAsList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ open class SqliteBankingRepository : BankingRepository {
|
||||||
return bankQueries.transactionWithResult {
|
return bankQueries.transactionWithResult {
|
||||||
bankQueries.insertBank(bank.domesticBankCode, 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.customerName, bank.userId, bank.selectedTanMethodIdentifier, bank.selectedTanMediumIdentifier,
|
||||||
bank.bankingGroup?.name, bank.serverAddress, bank.countryCode, null, bank.userSetDisplayName, bank.displayIndex.toLong(), bank.iconUrl, bank.wrongCredentialsEntered
|
bank.bankingGroup?.name, bank.serverAddress, bank.countryCode, bank.clientData, bank.userSetDisplayName, bank.displayIndex.toLong(), bank.iconUrl, bank.wrongCredentialsEntered
|
||||||
)
|
)
|
||||||
|
|
||||||
val bankId = getLastInsertedId() // getLastInsertedId() / last_insert_rowid() has to be called in a transaction with the insert operation, otherwise it will not work
|
val bankId = getLastInsertedId() // getLastInsertedId() / last_insert_rowid() has to be called in a transaction with the insert operation, otherwise it will not work
|
||||||
|
@ -141,6 +141,14 @@ open class SqliteBankingRepository : BankingRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun updateBank(bank: BankAccessEntity, clientData: String?) {
|
||||||
|
bankQueries.transaction {
|
||||||
|
if (clientData != null) {
|
||||||
|
bankQueries.updateBankClientData(clientData, bank.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) {
|
override suspend fun updateAccount(account: BankAccountEntity, userSetDisplayName: String?, hideAccount: Boolean, includeInAutomaticAccountsUpdate: Boolean) {
|
||||||
bankQueries.transaction {
|
bankQueries.transaction {
|
||||||
if (account.userSetDisplayName != userSetDisplayName) {
|
if (account.userSetDisplayName != userSetDisplayName) {
|
||||||
|
|
|
@ -32,7 +32,9 @@ class BankAccessEntity(
|
||||||
displayIndex: Int = 0,
|
displayIndex: Int = 0,
|
||||||
|
|
||||||
iconUrl: String? = null,
|
iconUrl: String? = null,
|
||||||
wrongCredentialsEntered: Boolean = false
|
wrongCredentialsEntered: Boolean = false,
|
||||||
|
|
||||||
|
clientData: String? = null
|
||||||
) : BankAccess(domesticBankCode, loginName, password, bankName, bic, customerName, userId, accounts, selectedTanMethodIdentifier, tanMethods, selectedTanMediumIdentifier, tanMedia, bankingGroup, serverAddress, countryCode) {
|
) : BankAccess(domesticBankCode, loginName, password, bankName, bic, customerName, userId, accounts, selectedTanMethodIdentifier, tanMethods, selectedTanMediumIdentifier, tanMedia, bankingGroup, serverAddress, countryCode) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -41,6 +43,8 @@ class BankAccessEntity(
|
||||||
|
|
||||||
this.iconUrl = iconUrl
|
this.iconUrl = iconUrl
|
||||||
this.wrongCredentialsEntered = wrongCredentialsEntered
|
this.wrongCredentialsEntered = wrongCredentialsEntered
|
||||||
|
|
||||||
|
this.clientData = clientData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,12 @@ SET userSetDisplayName = ?
|
||||||
WHERE id = ?;
|
WHERE id = ?;
|
||||||
|
|
||||||
|
|
||||||
|
updateBankClientData:
|
||||||
|
UPDATE BankAccess
|
||||||
|
SET clientData = ?
|
||||||
|
WHERE id = ?;
|
||||||
|
|
||||||
|
|
||||||
deleteBank {
|
deleteBank {
|
||||||
DELETE FROM TanMethod
|
DELETE FROM TanMethod
|
||||||
WHERE bankId = :bankId;
|
WHERE bankId = :bankId;
|
||||||
|
|
|
@ -281,6 +281,8 @@ class BankingService(
|
||||||
bankingRepository.updateAccount(account, response.balance ?: account.balance, response.transactionsRetrievalTime, response.retrievedTransactionsFrom ?: account.retrievedTransactionsFrom)
|
bankingRepository.updateAccount(account, response.balance ?: account.balance, response.transactionsRetrievalTime, response.retrievedTransactionsFrom ?: account.retrievedTransactionsFrom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bankingRepository.updateBank(bank, bank.clientData)
|
||||||
|
|
||||||
notifyBanksListUpdated() // notify about updated values like account balance
|
notifyBanksListUpdated() // notify about updated values like account balance
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
log.error(e) { "Could not save updated account transactions for bank $bank" }
|
log.error(e) { "Could not save updated account transactions for bank $bank" }
|
||||||
|
|
Loading…
Reference in New Issue