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) {