Introduced a new `ReadDocumentDetailsQuery` to fetch document metadata (`DocumentDetailsDto`) without the binary payload. Updated `MappingProfile` to map `Document` to `DocumentDetailsDto`. Refactored `DocumentService` to handle separate fetching of metadata and binary data, combining them into `DocumentDto`. Changed the metadata endpoint to `/api/Document/details`. Added a new `GetDocumentDetails` endpoint in `DocumentController` to return metadata without binary data. Updated `EnvelopeReceiverPageDataService` with a new method `GetDocumentMetadataOfSenderAsync` for fetching metadata. These changes improve efficiency by allowing clients to load metadata without transferring large binary data when unnecessary.
45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using AutoMapper;
|
|
using AutoMapper.QueryableExtensions;
|
|
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using EnvelopeGenerator.Application.Common.Dto;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace EnvelopeGenerator.Application.Documents.Queries;
|
|
|
|
/// <summary>
|
|
/// Represents a query to read document metadata/details without binary payload.
|
|
/// </summary>
|
|
/// <param name="EnvelopeId">The identifier of the envelope associated with the document.</param>
|
|
/// <param name="UserId">The unique identifier of the sending user. Optional.</param>
|
|
public record ReadDocumentDetailsQuery(int EnvelopeId, int? UserId = null) : IRequest<DocumentDetailsDto?>;
|
|
|
|
/// <summary>
|
|
/// Handles queries for reading document details without loading BYTE_DATA.
|
|
/// </summary>
|
|
public class ReadDocumentDetailsQueryHandler : IRequestHandler<ReadDocumentDetailsQuery, DocumentDetailsDto?>
|
|
{
|
|
private readonly IRepository<Document> _repo;
|
|
private readonly IMapper _mapper;
|
|
|
|
public ReadDocumentDetailsQueryHandler(IRepository<Document> repo, IMapper mapper)
|
|
{
|
|
_repo = repo;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
public async Task<DocumentDetailsDto?> Handle(ReadDocumentDetailsQuery query, CancellationToken cancel)
|
|
{
|
|
var docQuery = _repo.Query.AsNoTracking();
|
|
|
|
if (query.UserId is int userId)
|
|
docQuery = docQuery.Where(doc => doc.Envelope.UserId == userId);
|
|
|
|
return await docQuery
|
|
.Where(d => d.EnvelopeId == query.EnvelopeId)
|
|
.ProjectTo<DocumentDetailsDto>(_mapper.ConfigurationProvider)
|
|
.FirstOrDefaultAsync(cancel);
|
|
}
|
|
}
|