Refactor FinalizeDocumentJob to use async repository access

Replaced EnvelopeModel with IRepository<Envelope> in FinalizeDocumentJob, switching to dependency-injected, repository-based, and asynchronous data access using Entity Framework. Updated envelope retrieval to use SingleOrDefaultAsync, improving maintainability and scalability. Added necessary using directives to support these changes.
This commit is contained in:
2026-03-06 14:53:00 +01:00
parent 0ee7ec82d6
commit c88e7b2b9e

View File

@@ -11,11 +11,14 @@ using EnvelopeGenerator.ServiceHost.Extensions;
using MediatR;
using EnvelopeGenerator.Application.Configuration.Queries;
using EnvelopeGenerator.Application.Common.Dto;
using EnvelopeGenerator.Application.Envelopes.Queries;
using DigitalData.Core.Abstraction.Application.Repository;
using Microsoft.EntityFrameworkCore;
namespace EnvelopeGenerator.ServiceHost.Jobs;
[Obsolete("ActionService is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration config, ILogger<FinalizeDocumentJob> logger, TempFiles tempFiles, ActionService actionService, PDFBurner pdfBurner, PDFMerger pdfMerger, ReportCreator reportCreator, EnvelopeModel _envelopeModel, ReportModel _reportModel, MSSQLServer _database, GdViewer? _gdViewer, LicenseManager licenseManager, IMediator mediator)
public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration config, ILogger<FinalizeDocumentJob> logger, TempFiles tempFiles, ActionService actionService, PDFBurner pdfBurner, PDFMerger pdfMerger, ReportCreator reportCreator, ReportModel _reportModel, MSSQLServer _database, GdViewer? _gdViewer, LicenseManager licenseManager, IMediator mediator, IRepository<Envelope> envRepo)
{
private readonly WorkerOptions _options = options.Value;
@@ -69,7 +72,7 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
logger.LogInformation("Finalizing Envelope [{id}] ({current}/{total})", id, current, total);
try
{
var envelope = _envelopeModel?.GetById(id);
var envelope = await envRepo.Where(e => e.Id == id).SingleOrDefaultAsync(cancel);
if (envelope is null)
{
logger.LogWarning("Envelope could not be loaded for Id [{id}]!", id);