feat(ReceiverAlreadySignedQuery): create with handler

This commit is contained in:
tekh 2025-08-22 21:34:33 +02:00
parent 30e2ac602d
commit bd7c1d4e36
2 changed files with 93 additions and 2 deletions

View File

@ -85,11 +85,20 @@ public record ReadEnvelopeReceiverQuery : IRequest<IEnumerable<EnvelopeReceiverD
public ReadReceiverQuery? Receiver { get; set; }
};
/// <summary>
///
/// </summary>
public static class Extensions
{
public static Task<EnvelopeReceiverDto?> ReadEnvelopeReceiverAsync(this IMediator mediator, string key)
/// <summary>
///
/// </summary>
/// <param name="mediator"></param>
/// <param name="key"></param>
/// <returns></returns>
public static Task<EnvelopeReceiverDto?> 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());
}
}

View File

@ -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;
/// <summary>
///
/// </summary>
public record ReceiverAlreadySignedQuery : IRequest<bool>
{
/// <summary>
///
/// </summary>
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!;
}
/// <summary>
///
/// </summary>
public static class ReceiverAlreadySignedQueryExtensions
{
/// <summary>
///
/// </summary>
/// <param name="mediator"></param>
/// <param name="key"></param>
/// <returns></returns>
public static Task<bool> ReceiverAlreadySigned(IMediator mediator, string key)
=> mediator.Send(new ReceiverAlreadySignedQuery { Key = key });
}
/// <summary>
///
/// </summary>
public class ReceiverAlreadySignedQueryHandler : IRequestHandler<ReceiverAlreadySignedQuery, bool>
{
private readonly IRepository<EnvelopeReceiver> _repo;
/// <summary>
///
/// </summary>
/// <param name="repo"></param>
public ReceiverAlreadySignedQueryHandler(IRepository<EnvelopeReceiver> repo)
{
_repo = repo;
}
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="cancel"></param>
/// <returns></returns>
public async Task<bool> 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);
}
}