diff --git a/EnvelopeGenerator.ReceiverUI/Models/EnvelopeReceiverDto.cs b/EnvelopeGenerator.ReceiverUI/Models/EnvelopeReceiverDto.cs new file mode 100644 index 00000000..a646bfb3 --- /dev/null +++ b/EnvelopeGenerator.ReceiverUI/Models/EnvelopeReceiverDto.cs @@ -0,0 +1,106 @@ +namespace EnvelopeGenerator.ReceiverUI.Models; + +/// +/// Client-side model for the envelope receiver returned by +/// GET api/EnvelopeReceiver/{envelopeKey}. +/// +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; } +} + +/// +/// Client-side model for the envelope data embedded in . +/// +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? Documents { get; init; } + public EnvelopeSenderDto? User { get; init; } +} + +/// +/// Sender (user) information embedded in . +/// +public record EnvelopeSenderDto +{ + public int Id { get; init; } + public string? Username { get; init; } + public string? FullName { get; init; } + public string? Email { get; init; } +} + +/// +/// Client-side model for a document embedded in . +/// +public record DocumentClientDto +{ + public int Id { get; init; } + public int EnvelopeId { get; init; } + public DateTime AddedWhen { get; init; } + public IEnumerable? Elements { get; init; } +} + +/// +/// Client-side model for a signature/annotation element embedded in . +/// +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; } +} + +/// +/// Client-side model for the receiver data embedded in . +/// +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; } +} + diff --git a/EnvelopeGenerator.ReceiverUI/Services/EnvelopeReceiverService.cs b/EnvelopeGenerator.ReceiverUI/Services/EnvelopeReceiverService.cs new file mode 100644 index 00000000..ff275789 --- /dev/null +++ b/EnvelopeGenerator.ReceiverUI/Services/EnvelopeReceiverService.cs @@ -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; + +/// +/// Retrieves the for the authenticated receiver +/// from GET api/EnvelopeReceiver/{envelopeKey}. +/// +public class EnvelopeReceiverService(HttpClient http, IOptions apiOptions) +{ + private static readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerDefaults.Web); + + public async Task 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(_jsonOptions, cancel); + } +}