Implement backup and restore functionality; add IBackupService and BackupService; refactor services to use DbContextFactory
This commit is contained in:
@@ -8,13 +8,15 @@ namespace Duempelkas.Infrastructure.Services;
|
||||
|
||||
public class BalanceQueryService : IBalanceQueryService
|
||||
{
|
||||
private readonly FinanceDbContext _db;
|
||||
private readonly IDbContextFactory<FinanceDbContext> _dbFactory;
|
||||
|
||||
public BalanceQueryService(FinanceDbContext db) => _db = db;
|
||||
public BalanceQueryService(IDbContextFactory<FinanceDbContext> dbFactory) => _dbFactory = dbFactory;
|
||||
|
||||
public async Task<AccountBalanceDto> GetAccountBalanceAsync(int accountId)
|
||||
{
|
||||
var account = await _db.Accounts
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
var account = await db.Accounts
|
||||
.Include(a => a.Entries)
|
||||
.FirstOrDefaultAsync(a => a.Id == accountId)
|
||||
?? throw new InvalidOperationException($"Konto {accountId} nicht gefunden.");
|
||||
|
||||
Reference in New Issue
Block a user