diff --git a/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentQuery.cs b/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentQuery.cs
index 9f05f21a..be3fc0c6 100644
--- a/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentQuery.cs
+++ b/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentQuery.cs
@@ -7,6 +7,6 @@ namespace EnvelopeGenerator.Application.Documents.Queries.Read;
///
/// 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
+public record ReadDocumentQuery(int? Id = null, int? EnvelopeId = null) : IRequest
{
}
diff --git a/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentQueryHandler.cs b/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentQueryHandler.cs
index af4e1a74..b6e7d636 100644
--- a/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentQueryHandler.cs
+++ b/EnvelopeGenerator.Application/Documents/Queries/Read/ReadDocumentQueryHandler.cs
@@ -1,19 +1,48 @@
-using EnvelopeGenerator.Application.Contracts.Repositories;
+using DigitalData.Core.Abstractions.Infrastructure;
+using EnvelopeGenerator.Application.Contracts.Repositories;
+using EnvelopeGenerator.Domain.Entities;
using MediatR;
namespace EnvelopeGenerator.Application.Documents.Queries.Read;
-public class ReadDocumentQueryHandler : IRequestHandler
+///
+/// Handles queries for reading data based on either the document ID or the envelope ID.
+///
+public class ReadDocumentQueryHandler : IRequestHandler
{
- public IEnvelopeDocumentRepository _repo;
+ ///
+ /// Repository for accessing entities.
+ ///
+ private readonly IRepository _repo;
- public ReadDocumentQueryHandler(IEnvelopeDocumentRepository envelopeDocumentRepository)
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The repository used to access entities.
+ public ReadDocumentQueryHandler(IRepository envelopeDocumentRepository)
{
_repo = envelopeDocumentRepository;
}
- public Task Handle(ReadDocumentQuery query, CancellationToken cancellationToken)
+ ///
+ /// Handles the and returns a based on the provided identifiers.
+ ///
+ /// The query containing the document ID or envelope ID to search for.
+ /// A token to monitor for cancellation requests.
+ ///
+ /// A if a matching document is found; otherwise, null.
+ ///
+ ///
+ /// Thrown when neither nor is provided.
+ ///
+ public async Task Handle(ReadDocumentQuery query, CancellationToken cancellationToken)
{
- throw new NotImplementedException();
+ if (query.Id is not null)
+ return await _repo.ReadOrDefaultAsync(d => d.Id == query.Id);
+ else if (query.EnvelopeId is not null)
+ return await _repo.ReadOrDefaultAsync(d => d.EnvelopeId == query.EnvelopeId);
+
+ throw new InvalidOperationException(
+ $"Invalid {nameof(ReadDocumentQuery)}: either {nameof(query.Id)} or {nameof(query.EnvelopeId)} must be provided.");
}
}
diff --git a/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj b/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj
index 51b45346..c1eebe8f 100644
--- a/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj
+++ b/EnvelopeGenerator.Application/EnvelopeGenerator.Application.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/EnvelopeGenerator.Domain/EnvelopeGenerator.Domain.csproj b/EnvelopeGenerator.Domain/EnvelopeGenerator.Domain.csproj
index c7f0b01d..8a430d70 100644
--- a/EnvelopeGenerator.Domain/EnvelopeGenerator.Domain.csproj
+++ b/EnvelopeGenerator.Domain/EnvelopeGenerator.Domain.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/EnvelopeGenerator.GeneratorAPI/EnvelopeGenerator.GeneratorAPI.csproj b/EnvelopeGenerator.GeneratorAPI/EnvelopeGenerator.GeneratorAPI.csproj
index 8fcf50f7..6cf235f1 100644
--- a/EnvelopeGenerator.GeneratorAPI/EnvelopeGenerator.GeneratorAPI.csproj
+++ b/EnvelopeGenerator.GeneratorAPI/EnvelopeGenerator.GeneratorAPI.csproj
@@ -28,7 +28,7 @@
-
+
diff --git a/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj b/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj
index bf0554ea..f18a5f72 100644
--- a/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj
+++ b/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj
@@ -7,9 +7,9 @@
-
-
-
+
+
+
diff --git a/EnvelopeGenerator.Terminal/EnvelopeGenerator.Terminal.csproj b/EnvelopeGenerator.Terminal/EnvelopeGenerator.Terminal.csproj
index ec64e2f1..323f96d0 100644
--- a/EnvelopeGenerator.Terminal/EnvelopeGenerator.Terminal.csproj
+++ b/EnvelopeGenerator.Terminal/EnvelopeGenerator.Terminal.csproj
@@ -21,7 +21,7 @@
-
+
diff --git a/EnvelopeGenerator.Tests.Application/EnvelopeGenerator.Tests.Application.csproj b/EnvelopeGenerator.Tests.Application/EnvelopeGenerator.Tests.Application.csproj
index c6abb4a3..fecfd0e4 100644
--- a/EnvelopeGenerator.Tests.Application/EnvelopeGenerator.Tests.Application.csproj
+++ b/EnvelopeGenerator.Tests.Application/EnvelopeGenerator.Tests.Application.csproj
@@ -23,7 +23,7 @@
-
+
diff --git a/EnvelopeGenerator.Web/EnvelopeGenerator.Web.csproj b/EnvelopeGenerator.Web/EnvelopeGenerator.Web.csproj
index b1ba17ce..7b50de3b 100644
--- a/EnvelopeGenerator.Web/EnvelopeGenerator.Web.csproj
+++ b/EnvelopeGenerator.Web/EnvelopeGenerator.Web.csproj
@@ -2101,7 +2101,7 @@
-
+