Renamed namespaces and related identifiers from EnvelopeGenerator.WebUI to EnvelopeGenerator.Server across the project. This change affects data models, services, controllers, and configuration files to ensure consistency with the new architecture. Updated @using directives in Razor components and other files to reflect the new namespace structure. Adjusted project references in EnvelopeGenerator.Server.csproj to point to the new EnvelopeGenerator.Server.Client project. Modified middleware and logging configurations to use the new EnvelopeGenerator.Server namespace, including changes in Program.cs and appsettings.json. Updated resource and file references to use the new EnvelopeGenerator.Server path, ensuring correct resource loading. Adjusted configuration options in Program.cs to use the new namespace for options classes, such as ApiOptions and PdfViewerOptions. Updated authentication scheme names and related constants to align with the new namespace structure. Revised comments and documentation to reflect the new namespace, ensuring clarity and consistency in the codebase.
35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
using System.Net;
|
|
using System.Net.Http;
|
|
using Microsoft.Extensions.Options;
|
|
using EnvelopeGenerator.Server.Client.Options;
|
|
|
|
namespace EnvelopeGenerator.Server.Client.Services;
|
|
|
|
public class DocumentService(HttpClient http, IOptions<ApiOptions> apiOptions)
|
|
{
|
|
private readonly ApiOptions _api = apiOptions.Value;
|
|
|
|
/// <summary>
|
|
/// Fetches the PDF bytes for the given envelope key from the API.
|
|
/// Throws HttpRequestException on failure with appropriate status code.
|
|
/// </summary>
|
|
/// <exception cref="HttpRequestException">Thrown when the API request fails.</exception>
|
|
public async Task<byte[]?> GetDocumentAsync(string envelopeKey, CancellationToken cancel = default)
|
|
{
|
|
var response = await http.GetAsync($"{_api.BaseUrl}/api/Document/{Uri.EscapeDataString(envelopeKey)}", cancel);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
var statusCode = (int)response.StatusCode;
|
|
var reasonPhrase = response.ReasonPhrase ?? "Unknown error";
|
|
throw new HttpRequestException(
|
|
$"Failed to load document. Status: {statusCode} ({reasonPhrase})",
|
|
null,
|
|
response.StatusCode);
|
|
}
|
|
|
|
var bytes = await response.Content.ReadAsByteArrayAsync(cancel);
|
|
return bytes;
|
|
}
|
|
}
|