From 87bdef9d5e4f67b84cc45ec275df96154041641a Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 9 Jun 2026 18:12:12 +0200 Subject: [PATCH] Add SignCommand and handler for document signing 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` interface, with a placeholder `Handle` method delegating processing to pipeline behaviors. - Added necessary `using` directives for MediatR, DTOs, extensions, and constants. --- .../Signature/Commands/SignCommand.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 EnvelopeGenerator.Application/Signature/Commands/SignCommand.cs diff --git a/EnvelopeGenerator.Application/Signature/Commands/SignCommand.cs b/EnvelopeGenerator.Application/Signature/Commands/SignCommand.cs new file mode 100644 index 00000000..46cc8a22 --- /dev/null +++ b/EnvelopeGenerator.Application/Signature/Commands/SignCommand.cs @@ -0,0 +1,52 @@ +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; + +/// +/// Command to sign a document by a receiver. +/// +public record SignCommand : IRequest +{ + /// + /// The envelope receiver information. + /// + public required EnvelopeReceiverDto EnvelopeReceiver { get; init; } + + /// + /// The PSPDFKit annotation data. + /// + public PsPdfKitAnnotation? PsPdfKitAnnotation { get; init; } + + /// + /// Gets the email template type. + /// + public EmailTemplateType TemplateType => EmailTemplateType.DocumentSigned; + + /// + /// Gets the email address of the receiver. + /// + public string EmailAddress => EnvelopeReceiver.Receiver?.EmailAddress + ?? throw new InvalidOperationException($"Receiver is null." + + $"DocSignedNotification:\n{this.ToJson(Format.Json.ForDiagnostics)}"); +} + +/// +/// Handles the sign command. The actual work is done by SignCommandBehavior pipeline. +/// +public class SignCommandHandler : IRequestHandler +{ + /// + /// Executes the signing command. Pipeline behaviors handle the actual processing. + /// + /// + /// + /// + public Task Handle(SignCommand request, CancellationToken cancellationToken = default) + { + return Task.CompletedTask; + } +} \ No newline at end of file