Implemented deleting bank access
This commit is contained in:
parent
f365bfd883
commit
78edbd6d72
|
@ -26,6 +26,9 @@ interface BankingRepository {
|
||||||
|
|
||||||
suspend fun persistBank(bank: BankAccess): BankAccessEntity
|
suspend fun persistBank(bank: BankAccess): BankAccessEntity
|
||||||
|
|
||||||
|
suspend fun deleteBank(bank: BankAccessEntity)
|
||||||
|
|
||||||
|
|
||||||
suspend fun persistTransactions(bankAccount: BankAccountEntity, transactions: List<AccountTransaction>): List<AccountTransactionEntity>
|
suspend fun persistTransactions(bankAccount: BankAccountEntity, transactions: List<AccountTransaction>): List<AccountTransactionEntity>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,11 @@ class InMemoryBankingRepository(
|
||||||
return entity
|
return entity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun deleteBank(bank: BankAccessEntity) {
|
||||||
|
this.banks.remove(bank)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override suspend fun persistTransactions(bankAccount: BankAccountEntity, transactions: List<AccountTransaction>): List<AccountTransactionEntity> {
|
override suspend fun persistTransactions(bankAccount: BankAccountEntity, transactions: List<AccountTransaction>): List<AccountTransactionEntity> {
|
||||||
throw NotImplementedError("Lazy developer, method is not implemented")
|
throw NotImplementedError("Lazy developer, method is not implemented")
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,14 @@ open class SqliteBankingRepository : BankingRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun deleteBank(bank: BankAccessEntity) {
|
||||||
|
bankQueries.transaction {
|
||||||
|
accountTransactionQueries.deleteTransactionsByBankId(bankId = bank.id)
|
||||||
|
|
||||||
|
bankQueries.deleteBank(bank.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun getAllBankAccounts(): List<BankAccountEntity> = bankQueries.getAllBankAccounts { id, bankId, identifier, subAccountNumber, iban, productName, accountHolderName, type, currency, accountLimit, isAccountTypeSupportedByApplication, features, balance, serverTransactionsRetentionDays, lastAccountUpdateTime, retrievedTransactionsFrom, userSetDisplayName, displayIndex, hideAccount, includeInAutomaticAccountsUpdate ->
|
fun getAllBankAccounts(): List<BankAccountEntity> = bankQueries.getAllBankAccounts { id, bankId, identifier, subAccountNumber, iban, productName, accountHolderName, type, currency, accountLimit, isAccountTypeSupportedByApplication, features, balance, serverTransactionsRetentionDays, lastAccountUpdateTime, retrievedTransactionsFrom, userSetDisplayName, displayIndex, hideAccount, includeInAutomaticAccountsUpdate ->
|
||||||
BankAccountEntity(
|
BankAccountEntity(
|
||||||
|
|
|
@ -145,6 +145,15 @@ SELECT AccountTransaction.*
|
||||||
FROM AccountTransaction WHERE id = ?;
|
FROM AccountTransaction WHERE id = ?;
|
||||||
|
|
||||||
|
|
||||||
|
deleteTransactionsByBankId {
|
||||||
|
DELETE FROM BankAccount
|
||||||
|
WHERE bankId = :bankId;
|
||||||
|
|
||||||
|
DELETE FROM Holding
|
||||||
|
WHERE bankId = :bankId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS Holding (
|
CREATE TABLE IF NOT EXISTS Holding (
|
||||||
|
|
|
@ -79,6 +79,22 @@ SELECT BankAccess.*
|
||||||
FROM BankAccess;
|
FROM BankAccess;
|
||||||
|
|
||||||
|
|
||||||
|
deleteBank {
|
||||||
|
DELETE FROM TanMethod
|
||||||
|
WHERE bankId = :bankId;
|
||||||
|
|
||||||
|
DELETE FROM TanMedium
|
||||||
|
WHERE bankId = :bankId;
|
||||||
|
|
||||||
|
DELETE FROM BankAccount
|
||||||
|
WHERE bankId = :bankId;
|
||||||
|
|
||||||
|
DELETE FROM BankAccess
|
||||||
|
WHERE id = :bankId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS BankAccount (
|
CREATE TABLE IF NOT EXISTS BankAccount (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
|
@ -22,8 +22,10 @@ import net.codinux.banking.ui.forms.*
|
||||||
@Composable
|
@Composable
|
||||||
fun BaseDialog(
|
fun BaseDialog(
|
||||||
title: String,
|
title: String,
|
||||||
|
centerTitle: Boolean = false,
|
||||||
confirmButtonTitle: String = "OK",
|
confirmButtonTitle: String = "OK",
|
||||||
confirmButtonEnabled: Boolean = true,
|
confirmButtonEnabled: Boolean = true,
|
||||||
|
dismissButtonTitle: String = "Abbrechen",
|
||||||
showProgressIndicatorOnConfirmButton: Boolean = false,
|
showProgressIndicatorOnConfirmButton: Boolean = false,
|
||||||
useMoreThanPlatformDefaultWidthOnMobile: Boolean = false,
|
useMoreThanPlatformDefaultWidthOnMobile: Boolean = false,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
|
@ -38,7 +40,7 @@ fun BaseDialog(
|
||||||
Column(Modifier.background(Color.White).padding(8.dp)) {
|
Column(Modifier.background(Color.White).padding(8.dp)) {
|
||||||
|
|
||||||
Row(Modifier.fillMaxWidth()) {
|
Row(Modifier.fillMaxWidth()) {
|
||||||
HeaderText(title, Modifier.padding(top = 8.dp, bottom = 16.dp).weight(1f))
|
HeaderText(title, Modifier.fillMaxWidth().padding(top = 8.dp, bottom = 16.dp).weight(1f), textAlign = if (centerTitle) TextAlign.Center else TextAlign.Start)
|
||||||
|
|
||||||
if (DI.platform.isDesktop) {
|
if (DI.platform.isDesktop) {
|
||||||
TextButton(onDismiss, colors = ButtonDefaults.buttonColors(contentColor = Colors.Zinc700, backgroundColor = Color.Transparent)) {
|
TextButton(onDismiss, colors = ButtonDefaults.buttonColors(contentColor = Colors.Zinc700, backgroundColor = Color.Transparent)) {
|
||||||
|
@ -49,9 +51,9 @@ fun BaseDialog(
|
||||||
|
|
||||||
content()
|
content()
|
||||||
|
|
||||||
Row(Modifier.fillMaxWidth()) {
|
Row(Modifier.fillMaxWidth().padding(top = 8.dp)) {
|
||||||
TextButton(onClick = onDismiss, Modifier.weight(0.5f)) {
|
TextButton(onClick = onDismiss, Modifier.weight(0.5f)) {
|
||||||
Text("Abbrechen", color = Colors.CodinuxSecondaryColor, textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth())
|
Text(dismissButtonTitle, color = Colors.CodinuxSecondaryColor, textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth())
|
||||||
}
|
}
|
||||||
|
|
||||||
TextButton(
|
TextButton(
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package net.codinux.banking.ui.dialogs
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ConfirmDialog(
|
||||||
|
text: String,
|
||||||
|
title: String? = null,
|
||||||
|
confirmButtonTitle: String = "Ja",
|
||||||
|
dismissButtonTitle: String = "Nein",
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
onConfirm: () -> Unit
|
||||||
|
) {
|
||||||
|
|
||||||
|
BaseDialog(
|
||||||
|
title = title ?: "",
|
||||||
|
centerTitle = true,
|
||||||
|
confirmButtonTitle = confirmButtonTitle,
|
||||||
|
dismissButtonTitle = dismissButtonTitle,
|
||||||
|
onDismiss = { onDismiss() },
|
||||||
|
onConfirm = { onConfirm(); onDismiss() }
|
||||||
|
) {
|
||||||
|
Text(text, textAlign = TextAlign.Center, lineHeight = 22.sp, modifier = Modifier.fillMaxWidth().padding(bottom = 8.dp))
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import androidx.compose.ui.window.DialogProperties
|
||||||
import net.codinux.banking.ui.composables.text.HeaderText
|
import net.codinux.banking.ui.composables.text.HeaderText
|
||||||
import net.codinux.banking.ui.config.Colors
|
import net.codinux.banking.ui.config.Colors
|
||||||
import net.codinux.banking.ui.extensions.verticalScroll
|
import net.codinux.banking.ui.extensions.verticalScroll
|
||||||
|
import net.codinux.banking.ui.model.Config.NewLine
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ErrorDialog(
|
fun ErrorDialog(
|
||||||
|
@ -22,7 +23,7 @@ fun ErrorDialog(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val effectiveText = if (exception == null) text else {
|
val effectiveText = if (exception == null) text else {
|
||||||
"$text\r\n\r\nFehlermeldung:\r\n${exception.stackTraceToString()}"
|
"$text${NewLine}${NewLine}Fehlermeldung:${NewLine}${exception.stackTraceToString()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,20 @@ package net.codinux.banking.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
|
import androidx.compose.material.TextButton
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import net.codinux.banking.persistence.entities.BankAccessEntity
|
import net.codinux.banking.persistence.entities.BankAccessEntity
|
||||||
|
import net.codinux.banking.ui.config.Colors
|
||||||
import net.codinux.banking.ui.config.DI
|
import net.codinux.banking.ui.config.DI
|
||||||
|
import net.codinux.banking.ui.dialogs.ConfirmDialog
|
||||||
import net.codinux.banking.ui.extensions.verticalScroll
|
import net.codinux.banking.ui.extensions.verticalScroll
|
||||||
import net.codinux.banking.ui.forms.*
|
import net.codinux.banking.ui.forms.*
|
||||||
|
import net.codinux.banking.ui.model.Config.NewLine
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun BankSettingsScreen(bank: BankAccessEntity, onClosed: () -> Unit) {
|
fun BankSettingsScreen(bank: BankAccessEntity, onClosed: () -> Unit) {
|
||||||
|
@ -19,6 +26,10 @@ fun BankSettingsScreen(bank: BankAccessEntity, onClosed: () -> Unit) {
|
||||||
|
|
||||||
var enteredPassword by remember { mutableStateOf(bank.password ?: "") }
|
var enteredPassword by remember { mutableStateOf(bank.password ?: "") }
|
||||||
|
|
||||||
|
var showDeleteBankAccessConfirmationDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
val hasDataChanged by remember(enteredBankName) {
|
val hasDataChanged by remember(enteredBankName) {
|
||||||
mutableStateOf(
|
mutableStateOf(
|
||||||
(enteredBankName != bank.bankName && (bank.userSetDisplayName == null || enteredBankName != bank.userSetDisplayName))
|
(enteredBankName != bank.bankName && (bank.userSetDisplayName == null || enteredBankName != bank.userSetDisplayName))
|
||||||
|
@ -27,6 +38,21 @@ fun BankSettingsScreen(bank: BankAccessEntity, onClosed: () -> Unit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (showDeleteBankAccessConfirmationDialog) {
|
||||||
|
ConfirmDialog(
|
||||||
|
title = "${bank.displayName} wirklich löschen?",
|
||||||
|
text = "Dadurch werden auch alle zum Konto gehörenden Daten wie seine Kontoumsätze unwiderruflich gelöscht.${NewLine}Die Daten können nicht widerhergestellt werden.",
|
||||||
|
onDismiss = { showDeleteBankAccessConfirmationDialog = false },
|
||||||
|
onConfirm = {
|
||||||
|
coroutineScope.launch {
|
||||||
|
DI.bankingService.deleteBank(bank)
|
||||||
|
}
|
||||||
|
onClosed()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FullscreenViewBase(bank.displayName, onClosed = onClosed) {
|
FullscreenViewBase(bank.displayName, onClosed = onClosed) {
|
||||||
Column(Modifier.fillMaxSize().verticalScroll().padding(8.dp)) {
|
Column(Modifier.fillMaxSize().verticalScroll().padding(8.dp)) {
|
||||||
Column {
|
Column {
|
||||||
|
@ -98,13 +124,13 @@ fun BankSettingsScreen(bank: BankAccessEntity, onClosed: () -> Unit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spacer(Modifier.weight(1f))
|
Spacer(Modifier.weight(1f))
|
||||||
//
|
|
||||||
// Column(Modifier.padding(top = 18.dp, bottom = 18.dp)) {
|
Column(Modifier.padding(top = 24.dp, bottom = 18.dp)) {
|
||||||
// TextButton(modifier = Modifier.fillMaxWidth().height(50.dp), onClick = { }, enabled = false) {
|
TextButton(modifier = Modifier.fillMaxWidth().height(50.dp), onClick = { showDeleteBankAccessConfirmationDialog = true }) {
|
||||||
// Text("Konto löschen", color = Colors.DestructiveColor, textAlign = TextAlign.Center)
|
Text("Konto löschen", fontSize = 15.sp, color = Colors.DestructiveColor, textAlign = TextAlign.Center)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -93,6 +93,19 @@ class BankingService(
|
||||||
|
|
||||||
fun getAllBanks() = bankingRepository.getAllBanks()
|
fun getAllBanks() = bankingRepository.getAllBanks()
|
||||||
|
|
||||||
|
suspend fun deleteBank(bank: BankAccessEntity) {
|
||||||
|
try {
|
||||||
|
bankingRepository.deleteBank(bank)
|
||||||
|
|
||||||
|
uiState.transactions.value = uiState.transactions.value.filterNot { it.bankId == bank.id }
|
||||||
|
uiState.holdings.value = uiState.holdings.value.filterNot { it.bankId == bank.id }
|
||||||
|
uiState.banks.value = uiState.banks.value.toMutableList().also { it.remove(bank) }
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
log.error(e) { "Could not delete bank ${bank.displayName}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun getAllAccountTransactions() = bankingRepository.getAllAccountTransactions()
|
fun getAllAccountTransactions() = bankingRepository.getAllAccountTransactions()
|
||||||
|
|
||||||
fun getAllTransactionsForBank(bank: BankAccessEntity) = bankingRepository.getAllTransactionsForBank(bank)
|
fun getAllTransactionsForBank(bank: BankAccessEntity) = bankingRepository.getAllTransactionsForBank(bank)
|
||||||
|
|
Loading…
Reference in New Issue