Files
EnvelopeGenerator/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Services/SignatureCacheService.cs
TekH 106e62a912 Refactor namespaces to EnvelopeGenerator.Server
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.
2026-06-22 16:14:11 +02:00

67 lines
2.3 KiB
C#

using System.Net.Http.Json;
using Microsoft.Extensions.Options;
using EnvelopeGenerator.Server.Client.Options;
using EnvelopeGenerator.Server.Client.Models;
namespace EnvelopeGenerator.Server.Client.Services;
/// <summary>
/// Client service for managing cached signatures via API.
/// </summary>
public class SignatureCacheService(HttpClient http, IOptions<ApiOptions> apiOptions)
{
private readonly ApiOptions _api = apiOptions.Value;
public async Task SaveSignatureAsync(
string envelopeKey,
SignatureCaptureDto signature,
CancellationToken cancel = default)
{
var response = await http.PostAsJsonAsync(
$"{_api.BaseUrl}/api/Cache/SignatureCapture/{Uri.EscapeDataString(envelopeKey)}",
signature,
cancel);
if (!response.IsSuccessStatusCode)
{
var error = await response.Content.ReadAsStringAsync(cancel);
throw new HttpRequestException($"Failed to cache signature: {response.StatusCode} - {error}");
}
}
public async Task<SignatureCaptureDto?> GetSignatureAsync(
string envelopeKey,
CancellationToken cancel = default)
{
var response = await http.GetAsync(
$"{_api.BaseUrl}/api/Cache/SignatureCapture/{Uri.EscapeDataString(envelopeKey)}",
cancel);
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
return null;
if (!response.IsSuccessStatusCode)
{
var error = await response.Content.ReadAsStringAsync(cancel);
throw new HttpRequestException($"Failed to retrieve signature: {response.StatusCode} - {error}");
}
return await response.Content.ReadFromJsonAsync<SignatureCaptureDto>(cancellationToken: cancel);
}
public async Task DeleteSignatureAsync(
string envelopeKey,
CancellationToken cancel = default)
{
var response = await http.DeleteAsync(
$"{_api.BaseUrl}/api/Cache/SignatureCapture/{Uri.EscapeDataString(envelopeKey)}",
cancel);
if (!response.IsSuccessStatusCode)
{
var error = await response.Content.ReadAsStringAsync(cancel);
throw new HttpRequestException($"Failed to delete signature: {response.StatusCode} - {error}");
}
}
}