Add EnvelopeReceiverDto and related service class

Introduced `EnvelopeReceiverDto` and its nested models (`EnvelopeClientDto`, `EnvelopeSenderDto`, `DocumentClientDto`, `SignatureClientDto`, `ReceiverClientDto`) to represent client-side data for envelope receivers and their associated entities.

Added `EnvelopeReceiverService` to fetch `EnvelopeReceiverDto` from the API using `HttpClient`. Implemented error handling and JSON deserialization with `JsonSerializerDefaults.Web`. Updated necessary `using` directives.
This commit is contained in:
2026-06-01 03:56:02 +02:00
parent 360a762fb9
commit 122942a5ff
2 changed files with 133 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
using System.Net.Http.Json;
using System.Text.Json;
using EnvelopeGenerator.ReceiverUI.Models;
using EnvelopeGenerator.ReceiverUI.Options;
using Microsoft.Extensions.Options;
namespace EnvelopeGenerator.ReceiverUI.Services;
/// <summary>
/// Retrieves the <see cref="EnvelopeReceiverDto"/> for the authenticated receiver
/// from <c>GET api/EnvelopeReceiver/{envelopeKey}</c>.
/// </summary>
public class EnvelopeReceiverService(HttpClient http, IOptions<ApiOptions> apiOptions)
{
private static readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerDefaults.Web);
public async Task<EnvelopeReceiverDto?> GetAsync(string envelopeKey, CancellationToken cancel = default)
{
var url = $"{apiOptions.Value.BaseUrl}/api/EnvelopeReceiver/{Uri.EscapeDataString(envelopeKey)}";
var response = await http.GetAsync(url, cancel);
if (!response.IsSuccessStatusCode)
return null;
return await response.Content.ReadFromJsonAsync<EnvelopeReceiverDto>(_jsonOptions, cancel);
}
}