feat(history): enhance ReadHistoryQuery to support Envelope object and UUID
- Replace nullable `OnlyLast` with non-nullable default `true` - Support filtering by Envelope object (Id or Uuid) in addition to deprecated EnvelopeId - Throw `BadRequestException` if no valid Envelope reference is provided - Preserve status filtering and ordering for latest history entries
This commit is contained in:
parent
e5a061d5b5
commit
00c7fe5316
@ -24,7 +24,7 @@ public static class CountHistoryQueryExtensions
|
||||
/// <param name="queryOptions"></param>
|
||||
/// <param name="cancel"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<bool> AnyHistoryAsync(this ISender sender, Action<CountHistoryQuery> queryOptions, CancellationToken cancel)
|
||||
public static async Task<bool> AnyHistoryAsync(this ISender sender, Action<CountHistoryQuery> queryOptions, CancellationToken cancel = default)
|
||||
{
|
||||
var query = new CountHistoryQuery();
|
||||
queryOptions(query);
|
||||
@ -58,7 +58,19 @@ public class CountHistoryQueryHandler : IRequestHandler<CountHistoryQuery, int>
|
||||
/// <exception cref="NotFoundException"></exception>
|
||||
public Task<int> Handle(CountHistoryQuery request, CancellationToken cancel = default)
|
||||
{
|
||||
var query = _repo.Where(h => h.EnvelopeId == request.EnvelopeId);
|
||||
var query = _repo.Query;
|
||||
|
||||
if (request.Envelope.Id is int envId)
|
||||
query = query.Where(e => e.Id == envId);
|
||||
else if (request.Envelope.Uuid is string uuid)
|
||||
query = query.Where(e => e.Envelope!.Uuid == uuid);
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
else if (request.EnvelopeId is not null)
|
||||
query = query.Where(h => h.EnvelopeId == request.EnvelopeId);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
else
|
||||
throw new BadRequestException("Invalid request: An Envelope object or a valid EnvelopeId/UUID must be supplied.");
|
||||
|
||||
if (request.Status is not null)
|
||||
query = query.Where(h => h.Status == request.Status);
|
||||
|
||||
|
||||
@ -24,5 +24,5 @@ public record HistoryQueryBase
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public EnvelopeQueryBase? Envelope { get; set; }
|
||||
public EnvelopeQueryBase Envelope { get; set; } = new EnvelopeQueryBase();
|
||||
}
|
||||
@ -51,9 +51,9 @@ public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumer
|
||||
{
|
||||
var query = _repo.Query;
|
||||
|
||||
if (request.Envelope?.Id is int envId)
|
||||
if (request.Envelope.Id is int envId)
|
||||
query = query.Where(e => e.Id == envId);
|
||||
else if (request.Envelope?.Uuid is string uuid)
|
||||
else if (request.Envelope.Uuid is string uuid)
|
||||
query = query.Where(e => e.Envelope!.Uuid == uuid);
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
else if (request.EnvelopeId is not null)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user