Introduce `SignCommand` and `SignCommandHandler` in the `EnvelopeGenerator.Application.Signature.Commands` namespace. - `SignCommand` is a CQRS command that encapsulates the envelope receiver's information (`EnvelopeReceiverDto`) and optional PSPDFKit annotation data. - Added computed properties for email template type (`TemplateType`) and receiver's email address (`EmailAddress`), with validation for null receivers. - `SignCommandHandler` implements the `IRequestHandler<SignCommand>` interface, with a placeholder `Handle` method delegating processing to pipeline behaviors. - Added necessary `using` directives for MediatR, DTOs, extensions, and constants.
52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using MediatR;
|
|
using EnvelopeGenerator.Application.Common.Dto;
|
|
using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver;
|
|
using EnvelopeGenerator.Application.Common.Extensions;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
|
|
namespace EnvelopeGenerator.Application.Signature.Commands;
|
|
|
|
/// <summary>
|
|
/// Command to sign a document by a receiver.
|
|
/// </summary>
|
|
public record SignCommand : IRequest
|
|
{
|
|
/// <summary>
|
|
/// The envelope receiver information.
|
|
/// </summary>
|
|
public required EnvelopeReceiverDto EnvelopeReceiver { get; init; }
|
|
|
|
/// <summary>
|
|
/// The PSPDFKit annotation data.
|
|
/// </summary>
|
|
public PsPdfKitAnnotation? PsPdfKitAnnotation { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the email template type.
|
|
/// </summary>
|
|
public EmailTemplateType TemplateType => EmailTemplateType.DocumentSigned;
|
|
|
|
/// <summary>
|
|
/// Gets the email address of the receiver.
|
|
/// </summary>
|
|
public string EmailAddress => EnvelopeReceiver.Receiver?.EmailAddress
|
|
?? throw new InvalidOperationException($"Receiver is null." +
|
|
$"DocSignedNotification:\n{this.ToJson(Format.Json.ForDiagnostics)}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles the sign command. The actual work is done by SignCommandBehavior pipeline.
|
|
/// </summary>
|
|
public class SignCommandHandler : IRequestHandler<SignCommand>
|
|
{
|
|
/// <summary>
|
|
/// Executes the signing command. Pipeline behaviors handle the actual processing.
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public Task Handle(SignCommand request, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
} |