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:
106
EnvelopeGenerator.ReceiverUI/Models/EnvelopeReceiverDto.cs
Normal file
106
EnvelopeGenerator.ReceiverUI/Models/EnvelopeReceiverDto.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
namespace EnvelopeGenerator.ReceiverUI.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Client-side model for the envelope receiver returned by
|
||||
/// <c>GET api/EnvelopeReceiver/{envelopeKey}</c>.
|
||||
/// </summary>
|
||||
public record EnvelopeReceiverDto
|
||||
{
|
||||
public int EnvelopeId { get; init; }
|
||||
public int ReceiverId { get; init; }
|
||||
public int Sequence { get; init; }
|
||||
|
||||
public string? Name { get; init; }
|
||||
public string? JobTitle { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
public string? PrivateMessage { get; init; }
|
||||
|
||||
public DateTime AddedWhen { get; init; }
|
||||
public DateTime? ChangedWhen { get; init; }
|
||||
public bool HasPhoneNumber { get; init; }
|
||||
|
||||
public EnvelopeClientDto? Envelope { get; init; }
|
||||
public ReceiverClientDto? Receiver { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client-side model for the envelope data embedded in <see cref="EnvelopeReceiverDto"/>.
|
||||
/// </summary>
|
||||
public record EnvelopeClientDto
|
||||
{
|
||||
public int Id { get; init; }
|
||||
public int UserId { get; init; }
|
||||
public int Status { get; init; }
|
||||
public string StatusName { get; init; } = string.Empty;
|
||||
public string Uuid { get; init; } = string.Empty;
|
||||
public string Title { get; init; } = string.Empty;
|
||||
public string Message { get; init; } = string.Empty;
|
||||
public DateTime AddedWhen { get; init; }
|
||||
public DateTime? ChangedWhen { get; init; }
|
||||
public string Language { get; init; } = "de-DE";
|
||||
public int? EnvelopeTypeId { get; init; }
|
||||
public string? EnvelopeTypeTitle { get; init; }
|
||||
public int? ContractType { get; init; }
|
||||
public int? CertificationType { get; init; }
|
||||
public bool UseAccessCode { get; init; }
|
||||
public bool TFAEnabled { get; init; }
|
||||
public IEnumerable<DocumentClientDto>? Documents { get; init; }
|
||||
public EnvelopeSenderDto? User { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sender (user) information embedded in <see cref="EnvelopeClientDto"/>.
|
||||
/// </summary>
|
||||
public record EnvelopeSenderDto
|
||||
{
|
||||
public int Id { get; init; }
|
||||
public string? Username { get; init; }
|
||||
public string? FullName { get; init; }
|
||||
public string? Email { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client-side model for a document embedded in <see cref="EnvelopeClientDto"/>.
|
||||
/// </summary>
|
||||
public record DocumentClientDto
|
||||
{
|
||||
public int Id { get; init; }
|
||||
public int EnvelopeId { get; init; }
|
||||
public DateTime AddedWhen { get; init; }
|
||||
public IEnumerable<SignatureClientDto>? Elements { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client-side model for a signature/annotation element embedded in <see cref="DocumentClientDto"/>.
|
||||
/// </summary>
|
||||
public record SignatureClientDto
|
||||
{
|
||||
public int Id { get; init; }
|
||||
public int DocumentId { get; init; }
|
||||
public int ReceiverId { get; init; }
|
||||
public int ElementType { get; init; }
|
||||
public double X { get; init; }
|
||||
public double Y { get; init; }
|
||||
public double Width { get; init; }
|
||||
public double Height { get; init; }
|
||||
public int Page { get; init; }
|
||||
public bool Required { get; init; }
|
||||
public string? Tooltip { get; init; }
|
||||
public bool ReadOnly { get; init; }
|
||||
public int AnnotationIndex { get; init; }
|
||||
public DateTime AddedWhen { get; init; }
|
||||
public DateTime? ChangedWhen { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Client-side model for the receiver data embedded in <see cref="EnvelopeReceiverDto"/>.
|
||||
/// </summary>
|
||||
public record ReceiverClientDto
|
||||
{
|
||||
public int Id { get; init; }
|
||||
public string? EmailAddress { get; init; }
|
||||
public string? Signature { get; init; }
|
||||
public DateTime AddedWhen { get; init; }
|
||||
public DateTime? TfaRegDeadline { get; init; }
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user