Implement backup and restore functionality; add IBackupService and BackupService; refactor services to use DbContextFactory
This commit is contained in:
@@ -12,15 +12,15 @@ namespace Duempelkas.Infrastructure.Services;
|
||||
|
||||
public class PdfStatementService : IPdfStatementService
|
||||
{
|
||||
private readonly FinanceDbContext _db;
|
||||
private readonly IDbContextFactory<FinanceDbContext> _dbFactory;
|
||||
private readonly IEntryService _entryService;
|
||||
private readonly IBalanceQueryService _balanceQueryService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private static readonly CultureInfo DeLocale = new("de-DE");
|
||||
|
||||
public PdfStatementService(FinanceDbContext db, IEntryService entryService, IBalanceQueryService balanceQueryService, ISettingsService settingsService)
|
||||
public PdfStatementService(IDbContextFactory<FinanceDbContext> dbFactory, IEntryService entryService, IBalanceQueryService balanceQueryService, ISettingsService settingsService)
|
||||
{
|
||||
_db = db;
|
||||
_dbFactory = dbFactory;
|
||||
_entryService = entryService;
|
||||
_balanceQueryService = balanceQueryService;
|
||||
_settingsService = settingsService;
|
||||
@@ -28,7 +28,9 @@ public class PdfStatementService : IPdfStatementService
|
||||
|
||||
public async Task<byte[]> GenerateStatementAsync(int accountId, bool currentYearOnly)
|
||||
{
|
||||
var account = await _db.Accounts.FindAsync(accountId)
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
var account = await db.Accounts.FindAsync(accountId)
|
||||
?? throw new InvalidOperationException($"Konto {accountId} nicht gefunden.");
|
||||
|
||||
var entries = await _entryService.GetEntriesAsync(accountId, currentYearOnly);
|
||||
|
||||
Reference in New Issue
Block a user