diff --git a/EnvelopeGenerator.Application/DocReceiverElements/Queries/ReadDocReceiverElementQuery.cs b/EnvelopeGenerator.Application/DocReceiverElements/Queries/ReadDocReceiverElementQuery.cs new file mode 100644 index 00000000..3139051b --- /dev/null +++ b/EnvelopeGenerator.Application/DocReceiverElements/Queries/ReadDocReceiverElementQuery.cs @@ -0,0 +1,66 @@ +using AutoMapper; +using EnvelopeGenerator.Application.Common.Dto; +using EnvelopeGenerator.Application.Common.Query; +using EnvelopeGenerator.Domain.Entities; +using MediatR; +using EnvelopeGenerator.Application.Common.Extensions; +using DigitalData.Core.Abstraction.Application.Repository; +using Microsoft.EntityFrameworkCore; + +namespace EnvelopeGenerator.Application.DocReceiverElements.Queries; + +/// +/// +/// +public record ReadDocReceiverElementQuery : EnvelopeReceiverQueryBase, IRequest> +{ +} + +/// +/// +/// +public class ReadDocReceiverElementQueryHandler : IRequestHandler> +{ + private readonly IRepository _repository; + + private readonly IMapper _mapper; + + /// + /// + /// + /// + /// + public ReadDocReceiverElementQueryHandler(IRepository repository, IMapper mapper) + { + _repository = repository; + _mapper = mapper; + } + + /// + /// + /// + /// + /// + /// + /// + public async Task> Handle(ReadDocReceiverElementQuery request, CancellationToken cancellationToken) + { + var q = _repository.Query; + + if(request.Envelope.Id is int envelopeId) + q = q.Where(e => e.Document.EnvelopeId == envelopeId); + + if (request.Envelope.Uuid is string envelopeUuid) + q = q.Where(e => e.Document.Envelope.Uuid == envelopeUuid); + + if (request.Receiver.Id is int receiverId) + q = q.Where(e => e.ReceiverId == receiverId); + + if (request.Receiver.Signature is string signature) + q = q.Where(e => e.Receiver.Signature == signature); + + var elements = await q.ToListAsync(cancellationToken); + + return _mapper.Map>(elements); + } +} \ No newline at end of file