Replaced "EnvelopeGenerator.WebUI" with "EnvelopeGenerator.Server" and "EnvelopeGenerator.WebUI.Client" with "EnvelopeGenerator.Server.Client". Updated project entries, solution configuration platforms, and nested projects to reflect these changes.
67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
using System.Net.Http.Json;
|
|
using Microsoft.Extensions.Options;
|
|
using EnvelopeGenerator.WebUI.Client.Options;
|
|
using EnvelopeGenerator.WebUI.Client.Models;
|
|
|
|
namespace EnvelopeGenerator.WebUI.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}");
|
|
}
|
|
}
|
|
}
|