Added `ReceiverService` to the dependency injection container in `Program.cs` and implemented its functionality for fetching receiver email suggestions via API. Enhanced `DocumentService` with a new method `GetSenderDocumentDetailsByEnvelopeIdAsync` to fetch sender document details by envelope ID. Introduced JSON handling improvements with `JsonSerializerOptions`. These changes improve support for receiver-related operations and extend document-related capabilities.
30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
|
|
namespace EnvelopeGenerator.Server.Client.Services;
|
|
|
|
public class ReceiverService(IHttpClientFactory httpClientFactory)
|
|
{
|
|
private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);
|
|
|
|
/// <summary>
|
|
/// Fetches receiver email suggestions from sender-authorized API.
|
|
/// Calls GET /api/Receiver?EmailAddressSearch={term}&onlyEmailAddress=true.
|
|
/// </summary>
|
|
public async Task<IReadOnlyList<string>> SearchReceiverEmailsAsync(string searchTerm, CancellationToken cancel = default)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(searchTerm))
|
|
return [];
|
|
|
|
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
|
|
var url = $"/api/Receiver?EmailAddressSearch={Uri.EscapeDataString(searchTerm)}&onlyEmailAddress=true";
|
|
var response = await http.GetAsync(url, cancel);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
return [];
|
|
|
|
var emails = await response.Content.ReadFromJsonAsync<List<string>>(JsonOptions, cancel);
|
|
return emails ?? [];
|
|
}
|
|
}
|