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:
2026-10-02 10:56:47 +02:00
parent f558d03bdf
commit ec79d7622e
5 changed files with 95 additions and 12 deletions

View File

@@ -36,24 +36,41 @@ public class DocumentService(IHttpClientFactory httpClientFactory)
/// <summary>
/// Fetches sender document details (including signature elements) by envelope id.
/// Uses GET /api/Document?EnvelopeId={envelopeId}.
/// Uses GET /api/Document/details?EnvelopeId={envelopeId}.
/// </summary>
public async Task<DocumentDto?> GetSenderDocumentDetailsByEnvelopeIdAsync(int envelopeId, CancellationToken cancel = default)
{
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
var response = await http.GetAsync($"/api/Document?EnvelopeId={envelopeId}", cancel);
var detailsResponse = await http.GetAsync($"/api/Document/details?EnvelopeId={envelopeId}", cancel);
if (!response.IsSuccessStatusCode)
if (!detailsResponse.IsSuccessStatusCode)
{
var statusCode = (int)response.StatusCode;
var reasonPhrase = response.ReasonPhrase ?? "Unknown error";
var statusCode = (int)detailsResponse.StatusCode;
var reasonPhrase = detailsResponse.ReasonPhrase ?? "Unknown error";
throw new HttpRequestException(
$"Failed to load sender document details. Status: {statusCode} ({reasonPhrase})",
null,
response.StatusCode);
detailsResponse.StatusCode);
}
return await response.Content.ReadFromJsonAsync<DocumentDto>(_jsonOptions, cancel);
var details = await detailsResponse.Content.ReadFromJsonAsync<DocumentDetailsDto>(_jsonOptions, cancel)
?? throw new HttpRequestException("Failed to deserialize sender document details response.");
var bytesResponse = await http.GetAsync($"/api/Document?EnvelopeId={envelopeId}", cancel);
if (!bytesResponse.IsSuccessStatusCode)
{
var statusCode = (int)bytesResponse.StatusCode;
var reasonPhrase = bytesResponse.ReasonPhrase ?? "Unknown error";
throw new HttpRequestException(
$"Failed to load sender document bytes. Status: {statusCode} ({reasonPhrase})",
null,
bytesResponse.StatusCode);
}
var byteData = await bytesResponse.Content.ReadAsByteArrayAsync(cancel);
return new DocumentDto(byteData, details);
}
/// <summary>