feat(AddReportBehavior): add report creation logic to AddReportBehavior
- Added CreateReport method to generate PDF report from envelope data - Integrated call to CreateReport within pipeline after history creation - Introduced error handling via CreateReportException for missing report data - Added necessary using directives for EnvelopeReports, Exceptions, and Entities
This commit is contained in:
parent
6f9b5d4b13
commit
292b6b2ccf
@ -1,6 +1,9 @@
|
||||
using MediatR;
|
||||
using EnvelopeGenerator.Application.Histories.Commands;
|
||||
using EnvelopeGenerator.Domain.Constants;
|
||||
using EnvelopeGenerator.Application.EnvelopeReports;
|
||||
using EnvelopeGenerator.Application.Exceptions;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Pdf.Behaviors;
|
||||
|
||||
@ -40,6 +43,29 @@ public class AddReportBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
|
||||
Status = EnvelopeStatus.EnvelopeReportCreated,
|
||||
}, cancel);
|
||||
|
||||
docResult = await CreateReport(request.Envelope!, cancel);
|
||||
|
||||
return docResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="envelope"></param>
|
||||
/// <param name="cancel"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="CreateReportException"></exception>
|
||||
public async Task<byte[]> CreateReport(Envelope envelope, CancellationToken cancel)
|
||||
{
|
||||
var oItems = await _sender.ReadEnvelopeReportAsync(envelope.Id, cancel: cancel);
|
||||
|
||||
if (!oItems.Any())
|
||||
{
|
||||
throw new CreateReportException("No report data found!");
|
||||
}
|
||||
|
||||
var oBuffer = DoCreateReport(oItems);
|
||||
|
||||
return oBuffer;
|
||||
}
|
||||
}
|
||||
@ -22,6 +22,8 @@ namespace EnvelopeGenerator.Application.Pdf;
|
||||
public record BurnPdfCommand(int? EnvelopeId = null, string? EnvelopeUuid = null) : IRequest<byte[]>
|
||||
{
|
||||
internal bool Debug { get; set; }
|
||||
|
||||
internal Envelope? Envelope { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -102,13 +104,13 @@ public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand, byte[]>
|
||||
request.EnvelopeUuid is not null ? _envRepo.Where(env => env.Uuid == request.EnvelopeUuid) :
|
||||
throw new BadRequestException("Request validation failed: Either Envelope Id or Envelope Uuid must be provided.");
|
||||
|
||||
var envelope = await envQuery
|
||||
request.Envelope = await envQuery
|
||||
.Include(env => env.Documents!).ThenInclude(doc => doc.Elements!).ThenInclude(element => element.Annotations)
|
||||
.FirstOrDefaultAsync(cancel)
|
||||
?? throw new BadRequestException($"Envelope could not be found. Request details:\n" +
|
||||
request.ToJson(Format.Json.ForDiagnostics));
|
||||
|
||||
var doc = envelope.Documents?.FirstOrDefault()
|
||||
var doc = request.Envelope.Documents?.FirstOrDefault()
|
||||
?? throw new NotFoundException($"Document could not be located within the specified envelope. Request details:\n" +
|
||||
request.ToJson(Format.Json.ForDiagnostics));
|
||||
|
||||
@ -119,7 +121,7 @@ public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand, byte[]>
|
||||
return doc.Elements?.SelectMany(e => e.Annotations ?? Enumerable.Empty<ElementAnnotation>()).Where(annot => annot is not null).Any() ?? false
|
||||
? BurnElementAnnotsToPDF(doc.ByteData, doc.Elements)
|
||||
: BurnInstantJSONAnnotsToPDF(doc.ByteData, await _docStatusRepo
|
||||
.Where(status => status.EnvelopeId == envelope.Id)
|
||||
.Where(status => status.EnvelopeId == request.Envelope.Id)
|
||||
.Select(status => status.Value)
|
||||
.ToListAsync(cancel));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user