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.
28 lines
1.0 KiB
C#
28 lines
1.0 KiB
C#
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);
|
|
}
|
|
}
|