Introduced four new pipeline behaviors (`AnnotationBehavior`, `DocStatusBehavior`, `HistoryBehavior`, and `SendSignedMailBehavior`) to modularize the signing process. These behaviors handle annotation persistence, document status creation, history recording, and signed mail notifications, respectively. - `AnnotationBehavior`: Saves annotations using `IRepository`. - `DocStatusBehavior`: Creates document status via `ISender`. - `HistoryBehavior`: Records signing history and validates receiver information. - `SendSignedMailBehavior`: Sends signed mail notifications using email templates and dynamic placeholder replacement. Added error handling for missing data in `HistoryBehavior` and `SendSignedMailBehavior`. Updated the signing pipeline to execute these behaviors sequentially, ensuring a structured and extensible workflow.
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using EnvelopeGenerator.Application.Common.Extensions;
|
|
using EnvelopeGenerator.Application.Histories.Commands;
|
|
using EnvelopeGenerator.Application.Signature.Commands;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.Signature.Behaviors;
|
|
|
|
/// <summary>
|
|
/// Pipeline behavior that records history.
|
|
/// Executes third in the signing process.
|
|
/// </summary>
|
|
public class HistoryBehavior : IPipelineBehavior<SignCommand, Unit>
|
|
{
|
|
private readonly ISender _sender;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
public HistoryBehavior(ISender sender)
|
|
{
|
|
_sender = sender;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="next"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<Unit> Handle(SignCommand request, RequestHandlerDelegate<Unit> next, CancellationToken cancellationToken)
|
|
{
|
|
if (request.EnvelopeReceiver.Receiver is null)
|
|
throw new InvalidOperationException($"Receiver information is missing in the notification. SignCommand:\n {request.ToJson(Format.Json.ForDiagnostics)}");
|
|
|
|
await _sender.Send(new CreateHistoryCommand()
|
|
{
|
|
EnvelopeId = request.EnvelopeReceiver.EnvelopeId,
|
|
UserReference = request.EnvelopeReceiver.Receiver.EmailAddress,
|
|
Status = EnvelopeStatus.DocumentSigned,
|
|
}, cancellationToken);
|
|
|
|
return await next();
|
|
}
|
|
}
|