From ece676fbcf35f21dde162da9d2140e4534da1c23 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 5 Oct 2026 17:06:47 +0200 Subject: [PATCH] Make `Take` optional and refactor query handling logic Updated the `Take` property in `ReadRecentReceiverSuggestionsQuery` to be nullable, allowing for unlimited results when not specified. Refactored the `Handle` method in `ReadRecentReceiverSuggestionsQueryHandler` to conditionally apply the `Take` limit only when provided. Renamed the cancellation token parameter for consistency. Improved code clarity and flexibility by removing redundant operations and dynamically applying the `Take` logic. --- .../ReadRecentReceiverSuggestionsQuery.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReadRecentReceiverSuggestionsQuery.cs b/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReadRecentReceiverSuggestionsQuery.cs index f6cef12f..f2be96c0 100644 --- a/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReadRecentReceiverSuggestionsQuery.cs +++ b/EnvelopeGenerator.Application/EnvelopeReceivers/Queries/ReadRecentReceiverSuggestionsQuery.cs @@ -20,9 +20,9 @@ public record ReadRecentReceiverSuggestionsQuery : IRequest - /// Desired number of results. Default value is 5. + /// Desired number of results. /// - public int Take { get; init; } = 5; + public int? Take { get; init; } = null; /// /// Returns a new query instance scoped to the specified sender username. @@ -45,9 +45,9 @@ public class ReadRecentReceiverSuggestionsQueryHandler(IRepository /// Suggestion query. - /// Cancellation token. + /// Cancellation token. /// Ordered list of recent receiver suggestions. - public async Task> Handle(ReadRecentReceiverSuggestionsQuery request, CancellationToken cancellationToken) + public async Task> Handle(ReadRecentReceiverSuggestionsQuery request, CancellationToken cancel) { var query = repository.Query .AsNoTracking() @@ -80,7 +80,7 @@ public class ReadRecentReceiverSuggestionsQueryHandler(IRepository new { x.EmailAddress, x.LastUsedAt }) .Select(g => new RecentReceiverSuggestionDto { @@ -89,10 +89,10 @@ public class ReadRecentReceiverSuggestionsQueryHandler(IRepository x.LastUsedAt) - .ThenBy(x => x.EmailAddress) - .Take(request.Take) - .ToListAsync(cancellationToken); + .ThenBy(x => x.EmailAddress); - return suggestions; + return request.Take is int take + ? await suggestions.Take(take).ToListAsync(cancel) + : await suggestions.ToListAsync(cancel); } }