- 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
71 lines
2.0 KiB
C#
71 lines
2.0 KiB
C#
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;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class AddReportBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
|
|
{
|
|
private readonly ISender _sender;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
public AddReportBehavior(ISender sender)
|
|
{
|
|
_sender = sender;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="next"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
public async Task<byte[]> Handle(BurnPdfCommand request, RequestHandlerDelegate<byte[]> next, CancellationToken cancel)
|
|
{
|
|
var docResult = await next(cancel);
|
|
var base64 = Convert.ToBase64String(docResult);
|
|
|
|
if (!request.Debug)
|
|
await _sender.Send(new CreateHistoryCommand()
|
|
{
|
|
EnvelopeId = request.EnvelopeId,
|
|
UserReference = "System",
|
|
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;
|
|
}
|
|
} |