From 86758bb1275823c5c75e208f9f440a77f521849b Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 23 Sep 2026 15:28:55 +0200 Subject: [PATCH] feat(application): add UserId filter to ReadDocumentQuery Adds an optional UserId parameter to ReadDocumentQuery so callers can scope document lookups to envelopes owned by a specific sender. Also adds AsNoTracking() to the base query for read-only scenarios. --- .../Documents/Queries/ReadDocumentQuery.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/EnvelopeGenerator.Application/Documents/Queries/ReadDocumentQuery.cs b/EnvelopeGenerator.Application/Documents/Queries/ReadDocumentQuery.cs index 03b2d0f8..44eff6f4 100644 --- a/EnvelopeGenerator.Application/Documents/Queries/ReadDocumentQuery.cs +++ b/EnvelopeGenerator.Application/Documents/Queries/ReadDocumentQuery.cs @@ -13,7 +13,8 @@ namespace EnvelopeGenerator.Application.Documents.Queries; /// /// The unique identifier of the document. Optional. /// The identifier of the envelope associated with the document. Optional. -public record ReadDocumentQuery(int? Id = null, int? EnvelopeId = null) : IRequest +/// The unique identifier of the sending user. Optional. +public record ReadDocumentQuery(int? Id = null, int? EnvelopeId = null, int? UserId = null) : IRequest { } @@ -53,7 +54,10 @@ public class ReadDocumentQueryHandler : IRequestHandler public async Task Handle(ReadDocumentQuery query, CancellationToken cancel) { - var docQuery = _repo.Query.Include(doc => doc.Elements).ThenInclude(e => e.Annotations); + var docQuery = _repo.Query.Include(doc => doc.Elements).ThenInclude(e => e.Annotations).AsNoTracking(); + + if (query.UserId is int userId) + docQuery = docQuery.Where(doc => doc.Envelope.UserId == userId); if (query.Id is not null) {