From ade542ded089d976c89b9e6256426a96036a4840 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 1 Oct 2026 11:42:19 +0200 Subject: [PATCH] Add method to fetch document bytes by envelope ID Added `GetSenderDocumentBytesByEnvelopeIdAsync` to the `DocumentService` class. This method retrieves sender document bytes using an HTTP GET request to the endpoint `/api/Document?EnvelopeId={envelopeId}`. It handles HTTP response errors by throwing an `HttpRequestException` and supports cancellation via a `CancellationToken`. --- .../Services/DocumentService.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Services/DocumentService.cs b/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Services/DocumentService.cs index 1502225d..d6460a04 100644 --- a/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Services/DocumentService.cs +++ b/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Services/DocumentService.cs @@ -55,4 +55,26 @@ public class DocumentService(IHttpClientFactory httpClientFactory) return await response.Content.ReadFromJsonAsync(_jsonOptions, cancel); } + + /// + /// Fetches sender document bytes by envelope id. + /// Uses GET /api/Document?EnvelopeId={envelopeId}. + /// + public async Task GetSenderDocumentBytesByEnvelopeIdAsync(int envelopeId, CancellationToken cancel = default) + { + using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server"); + var response = await http.GetAsync($"/api/Document?EnvelopeId={envelopeId}", cancel); + + if (!response.IsSuccessStatusCode) + { + var statusCode = (int)response.StatusCode; + var reasonPhrase = response.ReasonPhrase ?? "Unknown error"; + throw new HttpRequestException( + $"Failed to load sender document bytes. Status: {statusCode} ({reasonPhrase})", + null, + response.StatusCode); + } + + return await response.Content.ReadAsByteArrayAsync(cancel); + } }