Add ReadDocReceiverElementQuery and handler
Introduced `ReadDocReceiverElementQuery` for retrieving document receiver elements and its corresponding handler. Added necessary `using` directives for dependencies like `AutoMapper`, `MediatR`, and `Microsoft.EntityFrameworkCore`. The handler dynamically filters `DocReceiverElement` data based on optional query parameters (e.g., `Envelope.Id`, `Envelope.Uuid`, `Receiver.Id`, `Receiver.Signature`) using LINQ. Data is fetched asynchronously and mapped to DTOs using `AutoMapper`.
This commit is contained in:
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public record ReadDocReceiverElementQuery : EnvelopeReceiverQueryBase, IRequest<IEnumerable<DocReceiverElementDto>>
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ReadDocReceiverElementQueryHandler : IRequestHandler<ReadDocReceiverElementQuery, IEnumerable<DocReceiverElementDto>>
|
||||
{
|
||||
private readonly IRepository<DocReceiverElement> _repository;
|
||||
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="repository"></param>
|
||||
/// <param name="mapper"></param>
|
||||
public ReadDocReceiverElementQueryHandler(IRepository<DocReceiverElement> repository, IMapper mapper)
|
||||
{
|
||||
_repository = repository;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<IEnumerable<DocReceiverElementDto>> 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<IEnumerable<DocReceiverElementDto>>(elements);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user