Refactor AuthService and add new service classes

Refactored `AuthService` to introduce a reusable `CreateDefaultClient` method, reducing code duplication. Updated all relevant methods in `AuthService` to use this new method.

Added `CultureService` to manage application culture/localization, including support for setting, getting, and initializing culture from `localStorage` or browser settings.

Introduced `DocReceiverElementService` for retrieving document receiver elements (signatures) and `EnvelopeService` for managing envelope data retrieval with optional filters. Both services include error handling and consistent JSON deserialization.

These changes improve code maintainability, reusability, and adhere to the single responsibility principle.
This commit is contained in:
2026-06-25 13:16:57 +02:00
parent 6aa97adf84
commit 78ed49a077
4 changed files with 179 additions and 7 deletions

View File

@@ -0,0 +1,24 @@
using System.Net.Http.Json;
using System.Text.Json;
using EnvelopeGenerator.Server.Client.Models;
using EnvelopeGenerator.Server.Client.Options;
using Microsoft.Extensions.Options;
namespace EnvelopeGenerator.Server.Client.Services;
public class DocReceiverElementService(HttpClient http, IOptions<ApiOptions> apiOptions)
{
private static readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerDefaults.Web);
public async Task<IReadOnlyList<SignatureDto>> GetAsync(string envelopeKey, CancellationToken cancel = default)
{
var url = $"{apiOptions.Value.BaseUrl}/api/DocReceiverElement/{Uri.EscapeDataString(envelopeKey)}";
var response = await http.GetAsync(url, cancel);
if (!response.IsSuccessStatusCode)
throw new HttpRequestException($"Failed to retrieve signatures for envelope {envelopeKey}: {response.StatusCode} {response.ReasonPhrase}");
var result = await response.Content.ReadFromJsonAsync<List<SignatureDto>>(_jsonOptions, cancel);
return result ?? [];
}
}