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:
@@ -11,11 +11,14 @@ using EnvelopeGenerator.ServiceHost.Extensions;
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using EnvelopeGenerator.Application.Configuration.Queries;
|
using EnvelopeGenerator.Application.Configuration.Queries;
|
||||||
using EnvelopeGenerator.Application.Common.Dto;
|
using EnvelopeGenerator.Application.Common.Dto;
|
||||||
|
using EnvelopeGenerator.Application.Envelopes.Queries;
|
||||||
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
|
||||||
[Obsolete("ActionService is a placeholder service added by copilot. Migrate the actual logic from CommonServices.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;
|
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);
|
logger.LogInformation("Finalizing Envelope [{id}] ({current}/{total})", id, current, total);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var envelope = _envelopeModel?.GetById(id);
|
var envelope = await envRepo.Where(e => e.Id == id).SingleOrDefaultAsync(cancel);
|
||||||
if (envelope is null)
|
if (envelope is null)
|
||||||
{
|
{
|
||||||
logger.LogWarning("Envelope could not be loaded for Id [{id}]!", id);
|
logger.LogWarning("Envelope could not be loaded for Id [{id}]!", id);
|
||||||
|
|||||||
Reference in New Issue
Block a user