Add support for fetching document metadata separately
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.
This commit is contained in:
@@ -31,17 +31,30 @@ public class DocumentController(IMediator mediator, IAuthorizationService authSe
|
||||
/// <param name="cancel">Cancellation token.</param>
|
||||
[HttpGet]
|
||||
[Authorize(AuthenticationSchemes = AuthScheme.Sender)]
|
||||
public async Task<IActionResult> GetDocument(CancellationToken cancel, [FromQuery] ReadDocumentQuery? query = null)
|
||||
public async Task<IActionResult> GetDocument(CancellationToken cancel, [FromQuery] ReadDocumentQuery query)
|
||||
{
|
||||
if (query is null)
|
||||
return BadRequest("Missing document query.");
|
||||
|
||||
var senderDoc = await mediator.Send(query, cancel);
|
||||
return senderDoc?.ByteData is byte[] senderDocByte
|
||||
? File(senderDocByte, "application/octet-stream")
|
||||
: NotFound("Document is empty.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns sender document metadata and element details (without binary payload) for editor loading.
|
||||
/// </summary>
|
||||
/// <param name="query">Document query with EnvelopeId.</param>
|
||||
/// <param name="cancel">Cancellation token.</param>
|
||||
[HttpGet("details")]
|
||||
[Authorize(AuthenticationSchemes = AuthScheme.Sender)]
|
||||
public async Task<IActionResult> GetDocumentDetails(CancellationToken cancel, [FromQuery] ReadDocumentDetailsQuery query)
|
||||
{
|
||||
var senderDoc = await mediator.Send(query with { UserId = User.GetId() }, cancel);
|
||||
if (senderDoc is null)
|
||||
return NotFound("Document is empty.");
|
||||
|
||||
return Ok(senderDoc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the document for the specified envelope key.
|
||||
/// </summary>
|
||||
|
||||
@@ -57,6 +57,14 @@ public class EnvelopeReceiverPageDataService(
|
||||
return await mediator.Send(new ReadDocumentQuery(EnvelopeId: envelopeId, UserId: user.SenderId()), cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads document metadata/elements for the authenticated sender without binary payload.
|
||||
/// </summary>
|
||||
public async Task<DocumentDetailsDto?> GetDocumentMetadataOfSenderAsync(ClaimsPrincipal user, int envelopeId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await mediator.Send(new ReadDocumentDetailsQuery(EnvelopeId: envelopeId, UserId: user.SenderId()), cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the current receiver's signature placeholders.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user