feat(ReadEnvelopeQuery): implement ReadEnvelopeQueryHandler with filtering support
- Added `ReadEnvelopeQueryHandler` to handle `ReadEnvelopeQuery`. - Supports filtering envelopes by: - Included and ignored `EnvelopeStatus` values. - Minimum and maximum status. - Presence or absence of `DocResult`. - Uses repository query extension methods and AutoMapper to map to `EnvelopeDto`.
This commit is contained in:
@@ -2,6 +2,11 @@
|
|||||||
using EnvelopeGenerator.Domain.Constants;
|
using EnvelopeGenerator.Domain.Constants;
|
||||||
using EnvelopeGenerator.Application.Common.Query;
|
using EnvelopeGenerator.Application.Common.Query;
|
||||||
using EnvelopeGenerator.Application.Common.Dto;
|
using EnvelopeGenerator.Application.Common.Dto;
|
||||||
|
using AutoMapper;
|
||||||
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using EnvelopeGenerator.Application.Common.Extensions;
|
||||||
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Envelopes.Queries;
|
namespace EnvelopeGenerator.Application.Envelopes.Queries;
|
||||||
|
|
||||||
@@ -72,3 +77,64 @@ public record EnvelopeStatusQuery
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public EnvelopeStatus[]? Ignore { get; init; }
|
public EnvelopeStatus[]? Ignore { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class ReadEnvelopeQueryHandler : IRequestHandler<ReadEnvelopeQuery, IEnumerable<EnvelopeDto>>
|
||||||
|
{
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
private readonly IRepository<Envelope> _repo;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mapper"></param>
|
||||||
|
/// <param name="repo"></param>
|
||||||
|
public ReadEnvelopeQueryHandler(IMapper mapper, IRepository<Envelope> repo)
|
||||||
|
{
|
||||||
|
_mapper = mapper;
|
||||||
|
_repo = repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancel"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="NotImplementedException"></exception>
|
||||||
|
public async Task<IEnumerable<EnvelopeDto>> Handle(ReadEnvelopeQuery request, CancellationToken cancel)
|
||||||
|
{
|
||||||
|
var q = _repo.Query.Where(request, notnull: false);
|
||||||
|
|
||||||
|
if (request.Status is EnvelopeStatusQuery statusQ)
|
||||||
|
{
|
||||||
|
// including status
|
||||||
|
if (statusQ.Include is EnvelopeStatus[] incStatus)
|
||||||
|
q = q.Where(e => incStatus.Contains(e.Status));
|
||||||
|
|
||||||
|
// ignoring status
|
||||||
|
if (statusQ.Ignore is EnvelopeStatus[] ignoreStatus)
|
||||||
|
q = q.Where(e => !ignoreStatus.Contains(e.Status));
|
||||||
|
|
||||||
|
// max status
|
||||||
|
if (statusQ.Max is EnvelopeStatus maxStatus)
|
||||||
|
q = q.Where(e => e.Status < maxStatus);
|
||||||
|
|
||||||
|
// min status
|
||||||
|
if (statusQ.Min is EnvelopeStatus minStatus)
|
||||||
|
q = q.Where(e => e.Status > minStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.HasDocResult is bool hasDocResult)
|
||||||
|
q = hasDocResult
|
||||||
|
? q.Where(e => e.DocResult != null)
|
||||||
|
: q.Where(e => e.DocResult == null);
|
||||||
|
|
||||||
|
var envelopes = await q.ToListAsync(cancel);
|
||||||
|
|
||||||
|
return _mapper.Map<IEnumerable<EnvelopeDto>>(envelopes);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user