From bd7c1d4e36ffd51409f8b703dc0c7bbaacd0b2ed Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 22 Aug 2025 21:34:33 +0200 Subject: [PATCH] feat(ReceiverAlreadySignedQuery): create with handler --- .../Queries/ReadEnvelopeReceiverQuery.cs | 13 ++- .../Queries/ReceiverAlreadySignedQuery.cs | 82 +++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReceiverAlreadySignedQuery.cs diff --git a/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReadEnvelopeReceiverQuery.cs b/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReadEnvelopeReceiverQuery.cs index 8d74455a..887cb20a 100644 --- a/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReadEnvelopeReceiverQuery.cs +++ b/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReadEnvelopeReceiverQuery.cs @@ -85,11 +85,20 @@ public record ReadEnvelopeReceiverQuery : IRequest +/// +/// public static class Extensions { - public static Task ReadEnvelopeReceiverAsync(this IMediator mediator, string key) + /// + /// + /// + /// + /// + /// + public static Task ReadEnvelopeReceiverAsync(this IMediator mediator, string key, CancellationToken cancel = default) { var q = new ReadEnvelopeReceiverQuery() { Key = key }; - return mediator.Send(q).Then(envRcvs => envRcvs.FirstOrDefault()); + return mediator.Send(q, cancel).Then(envRcvs => envRcvs.FirstOrDefault()); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReceiverAlreadySignedQuery.cs b/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReceiverAlreadySignedQuery.cs new file mode 100644 index 00000000..d83cde6f --- /dev/null +++ b/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReceiverAlreadySignedQuery.cs @@ -0,0 +1,82 @@ +using DigitalData.Core.Abstraction.Application.Repository; +using EnvelopeGenerator.Application.Exceptions; +using EnvelopeGenerator.Domain; +using EnvelopeGenerator.Domain.Entities; +using EnvelopeGenerator.Extensions; +using MediatR; +using Microsoft.EntityFrameworkCore; + +namespace EnvelopeGenerator.Application.EnvelopeReceivers.Queries; + +/// +/// +/// +public record ReceiverAlreadySignedQuery : IRequest +{ + /// + /// + /// + public required string Key + { + get => (EnvelopeUuid, ReceiverSignature).EncodeEnvelopeReceiverId(); + init + { + (string? EnvelopeUuid, string? ReceiverSignature) = value.DecodeEnvelopeReceiverId(); + if (string.IsNullOrEmpty(EnvelopeUuid) || string.IsNullOrEmpty(ReceiverSignature)) + { + throw new BadRequestException("Der EnvelopeReceiverKey muss ein gültiger Base64-kodierter String sein, der die EnvelopeUuid und die ReceiverSignature enthält."); + } + } + } + + internal string EnvelopeUuid { get; set; } = null!; + + internal string ReceiverSignature { get; set; } = null!; +} + +/// +/// +/// +public static class ReceiverAlreadySignedQueryExtensions +{ + /// + /// + /// + /// + /// + /// + public static Task ReceiverAlreadySigned(IMediator mediator, string key) + => mediator.Send(new ReceiverAlreadySignedQuery { Key = key }); +} + +/// +/// +/// +public class ReceiverAlreadySignedQueryHandler : IRequestHandler +{ + private readonly IRepository _repo; + + /// + /// + /// + /// + public ReceiverAlreadySignedQueryHandler(IRepository repo) + { + _repo = repo; + } + + /// + /// + /// + /// + /// + /// + public async Task Handle(ReceiverAlreadySignedQuery request, CancellationToken cancel = default) + { + return await _repo.Read() + .Where(er => er.Envelope.Uuid == request.EnvelopeUuid) + .Where(er => er.Receiver.Signature == request.ReceiverSignature) + .Where(er => er.Envelope.History.Any(hist => hist.Status == Constants.EnvelopeStatus.DocumentSigned)) + .AnyAsync(cancel); + } +} \ No newline at end of file