Implement account deletion
This commit is contained in:
parent
cbe2d5a556
commit
71993c2686
@ -179,7 +179,16 @@ class OkaneDatabase extends _$OkaneDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@DriftAccessor(tables: [Accounts])
|
@DriftAccessor(
|
||||||
|
tables: [
|
||||||
|
Accounts,
|
||||||
|
Transactions,
|
||||||
|
TransactionTemplates,
|
||||||
|
RecurringTransactions,
|
||||||
|
Budgets,
|
||||||
|
Beneficiaries,
|
||||||
|
],
|
||||||
|
)
|
||||||
class AccountsDao extends DatabaseAccessor<OkaneDatabase>
|
class AccountsDao extends DatabaseAccessor<OkaneDatabase>
|
||||||
with _$AccountsDaoMixin {
|
with _$AccountsDaoMixin {
|
||||||
AccountsDao(OkaneDatabase db) : super(db);
|
AccountsDao(OkaneDatabase db) : super(db);
|
||||||
@ -195,6 +204,22 @@ class AccountsDao extends DatabaseAccessor<OkaneDatabase>
|
|||||||
Future<int> upsertAccount(AccountsCompanion account) {
|
Future<int> upsertAccount(AccountsCompanion account) {
|
||||||
return into(accounts).insertOnConflictUpdate(account);
|
return into(accounts).insertOnConflictUpdate(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> removeAccount(Account account) async {
|
||||||
|
// Delete dependent data
|
||||||
|
await (delete(transactions)
|
||||||
|
..where((t) => t.accountId.equals(account.id))).go();
|
||||||
|
await (delete(recurringTransactions)
|
||||||
|
..where((r) => r.accountId.equals(account.id))).go();
|
||||||
|
await (delete(transactionTemplates)
|
||||||
|
..where((t) => t.accountId.equals(account.id))).go();
|
||||||
|
await (delete(budgets)..where((b) => b.accountId.equals(account.id))).go();
|
||||||
|
await (delete(beneficiaries)
|
||||||
|
..where((b) => b.accountId.equals(account.id))).go();
|
||||||
|
|
||||||
|
// Delete the account
|
||||||
|
await (delete(accounts)..where((a) => a.id.equals(account.id))).go();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TransactionQueryDateOption { thisMonth }
|
enum TransactionQueryDateOption { thisMonth }
|
||||||
|
@ -8190,6 +8190,15 @@ class $OkaneDatabaseManager {
|
|||||||
|
|
||||||
mixin _$AccountsDaoMixin on DatabaseAccessor<OkaneDatabase> {
|
mixin _$AccountsDaoMixin on DatabaseAccessor<OkaneDatabase> {
|
||||||
$AccountsTable get accounts => attachedDatabase.accounts;
|
$AccountsTable get accounts => attachedDatabase.accounts;
|
||||||
|
$ExpenseCategoriesTable get expenseCategories =>
|
||||||
|
attachedDatabase.expenseCategories;
|
||||||
|
$BeneficiariesTable get beneficiaries => attachedDatabase.beneficiaries;
|
||||||
|
$TransactionsTable get transactions => attachedDatabase.transactions;
|
||||||
|
$TransactionTemplatesTable get transactionTemplates =>
|
||||||
|
attachedDatabase.transactionTemplates;
|
||||||
|
$RecurringTransactionsTable get recurringTransactions =>
|
||||||
|
attachedDatabase.recurringTransactions;
|
||||||
|
$BudgetsTable get budgets => attachedDatabase.budgets;
|
||||||
}
|
}
|
||||||
mixin _$BeneficiariesDaoMixin on DatabaseAccessor<OkaneDatabase> {
|
mixin _$BeneficiariesDaoMixin on DatabaseAccessor<OkaneDatabase> {
|
||||||
$AccountsTable get accounts => attachedDatabase.accounts;
|
$AccountsTable get accounts => attachedDatabase.accounts;
|
||||||
|
@ -193,8 +193,7 @@ class CoreCubit extends Cubit<CoreState> {
|
|||||||
|
|
||||||
cancelStreams();
|
cancelStreams();
|
||||||
try {
|
try {
|
||||||
// TODO
|
await GetIt.I.get<OkaneDatabase>().accountsDao.removeAccount(account);
|
||||||
//await db.deleteAccount(account);
|
|
||||||
} finally {
|
} finally {
|
||||||
emit(state.copyWith(isDeletingAccount: false));
|
emit(state.copyWith(isDeletingAccount: false));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user