From 0c8d7f6b3c97d0be5888a9ece3a532cd72cdba0a Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 2 Mar 2026 16:17:21 +0100 Subject: [PATCH] Add 'Last' option to ReadResultViewQuery for latest result Added a Last property to ReadResultViewQuery to allow fetching only the most recent ResultView entity. Updated the handler logic to return either the last result or all results based on this property. --- src/ReC.Application/Results/Queries/ReadResultViewQuery.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ReC.Application/Results/Queries/ReadResultViewQuery.cs b/src/ReC.Application/Results/Queries/ReadResultViewQuery.cs index 4a65a4e..dcf5b4d 100644 --- a/src/ReC.Application/Results/Queries/ReadResultViewQuery.cs +++ b/src/ReC.Application/Results/Queries/ReadResultViewQuery.cs @@ -20,6 +20,8 @@ public record ReadResultViewQuery : IRequest> public bool IncludeAction { get; init; } = true; public bool IncludeProfile { get; init; } = false; + + public bool Last { get; init; } = false; } public class ReadResultViewQueryHandler(IRepository repo, IMapper mapper) : IRequestHandler> @@ -43,7 +45,7 @@ public class ReadResultViewQueryHandler(IRepository repo, IMapper ma if(request.IncludeProfile) q = q.Include(rv => rv.Profile); - var entities = await q.ToListAsync(cancel); + var entities = request.Last ? [await q.OrderBy(rv => rv.AddedWhen).LastOrDefaultAsync(cancel)] : await q.ToListAsync(cancel); if (entities.Count == 0) throw new NotFoundException($"No result views found for the given criteria. Criteria: {