fix(backup): use active SQLite database and validate safe restore (U01)
This commit is contained in:
@@ -11,7 +11,13 @@ public class AccountService : IAccountService
|
||||
{
|
||||
private readonly IDbContextFactory<FinanceDbContext> _dbFactory;
|
||||
|
||||
public AccountService(IDbContextFactory<FinanceDbContext> dbFactory) => _dbFactory = dbFactory;
|
||||
private readonly DatabaseLocation? _location;
|
||||
|
||||
public AccountService(IDbContextFactory<FinanceDbContext> dbFactory, DatabaseLocation? location = null)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
_location = location;
|
||||
}
|
||||
|
||||
public Task<List<AccountSummaryDto>> GetAllAccountsAsync()
|
||||
{
|
||||
@@ -20,6 +26,7 @@ public class AccountService : IAccountService
|
||||
|
||||
public async Task<List<AccountSummaryDto>> GetAllAccountsAsync(int? year)
|
||||
{
|
||||
using var lease = await DatabaseLease.AcquireAsync(_location);
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
var accounts = await db.Accounts
|
||||
@@ -71,6 +78,7 @@ public class AccountService : IAccountService
|
||||
|
||||
public async Task<AccountSummaryDto> GetAccountAsync(int accountId)
|
||||
{
|
||||
using var lease = await DatabaseLease.AcquireAsync(_location);
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
var account = await db.Accounts
|
||||
@@ -87,6 +95,7 @@ public class AccountService : IAccountService
|
||||
|
||||
public async Task<AccountSummaryDto> CreateAccountAsync(string name)
|
||||
{
|
||||
using var lease = await DatabaseLease.AcquireAsync(_location);
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
var account = new Account { Name = name };
|
||||
@@ -97,6 +106,7 @@ public class AccountService : IAccountService
|
||||
|
||||
public async Task RenameAccountAsync(int accountId, string newName)
|
||||
{
|
||||
using var lease = await DatabaseLease.AcquireAsync(_location);
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
var account = await db.Accounts.FindAsync(accountId)
|
||||
@@ -107,6 +117,7 @@ public class AccountService : IAccountService
|
||||
|
||||
public async Task UpdateCarryoverAsync(int accountId, decimal carryoverBalance)
|
||||
{
|
||||
using var lease = await DatabaseLease.AcquireAsync(_location);
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
var account = await db.Accounts.FindAsync(accountId)
|
||||
@@ -123,6 +134,7 @@ public class AccountService : IAccountService
|
||||
return;
|
||||
}
|
||||
|
||||
using var lease = await DatabaseLease.AcquireAsync(_location);
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
var account = await db.Accounts.FindAsync(accountId)
|
||||
@@ -138,6 +150,7 @@ public class AccountService : IAccountService
|
||||
|
||||
public async Task DeleteAccountAsync(int accountId)
|
||||
{
|
||||
using var lease = await DatabaseLease.AcquireAsync(_location);
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
var account = await db.Accounts
|
||||
|
||||
Reference in New Issue
Block a user