Refactor: Convert envelope query filters to LINQ query syntax
- Replaced multiple sequential 'Where' calls with a single LINQ query expression - Preserved all status filters (Include, Ignore, Min, Max) - Preserved DocResult filtering logic - Improves readability while keeping behavior identical
This commit is contained in:
parent
2b4573ea73
commit
db76162697
@ -107,33 +107,21 @@ public class ReadEnvelopeQueryHandler : IRequestHandler<ReadEnvelopeQuery, IEnum
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<IEnumerable<EnvelopeDto>> Handle(ReadEnvelopeQuery request, CancellationToken cancel)
|
||||
{
|
||||
var q = _repo.Query.Where(request, notnull: false);
|
||||
var envelopesQ = _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));
|
||||
EnvelopeStatusQuery? statusQ = request.Status;
|
||||
bool? hasDocResult = request.HasDocResult;
|
||||
|
||||
// ignoring status
|
||||
if (statusQ.Ignore is EnvelopeStatus[] ignoreStatus)
|
||||
q = q.Where(e => !ignoreStatus.Contains(e.Status));
|
||||
var filtered =
|
||||
from envelope in envelopesQ
|
||||
where (statusQ == null || statusQ.Include == null || statusQ.Include.Contains(envelope.Status))
|
||||
&& (statusQ == null || statusQ.Ignore == null || !statusQ.Ignore.Contains(envelope.Status))
|
||||
&& (statusQ == null || statusQ.Min == null || envelope.Status > statusQ.Min)
|
||||
&& (statusQ == null || statusQ.Max == null || envelope.Status < statusQ.Max)
|
||||
&& (!hasDocResult.HasValue || (hasDocResult.Value ? envelope.DocResult != null : envelope.DocResult == null))
|
||||
select envelope;
|
||||
|
||||
// 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);
|
||||
var envelopes = await filtered.ToListAsync(cancel);
|
||||
|
||||
return _mapper.Map<IEnumerable<EnvelopeDto>>(envelopes);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user