Refactor DTOs to classes with enhanced properties
Changed `EnvelopeReceiverReadOnlyDto` and `EnvelopeReceiverReadOnlyUpdateDto` from records to classes, converting properties to standard get/set accessors and adding documentation comments. Introduced a default value for `ChangedWhen` in `EnvelopeReceiverReadOnlyUpdateDto`. Modified `ReceiverCreateDto` to a class structure, updating properties to use init-only accessors and encapsulating SHA256 hash logic in a private field. Retained the `AddedWhen` property with its default value.
This commit is contained in:
@@ -3,21 +3,30 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace EnvelopeGenerator.Application.DTOs.Receiver
|
||||
{
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
public record ReceiverCreateDto([EmailAddress] string EmailAddress, string? TotpSecretkey = null)
|
||||
{
|
||||
public string Signature => sha256HexOfMail.Value;
|
||||
namespace EnvelopeGenerator.Application.DTOs.Receiver;
|
||||
|
||||
private readonly Lazy<string> sha256HexOfMail = new(() =>
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
public record ReceiverCreateDto
|
||||
{
|
||||
public ReceiverCreateDto()
|
||||
{
|
||||
_sha256HexOfMail = new(() =>
|
||||
{
|
||||
var bytes_arr = Encoding.UTF8.GetBytes(EmailAddress.ToUpper());
|
||||
var hash_arr = SHA256.HashData(bytes_arr);
|
||||
var hexa_str = BitConverter.ToString(hash_arr);
|
||||
return hexa_str.Replace("-", string.Empty);
|
||||
});
|
||||
}
|
||||
|
||||
public DateTime AddedWhen { get; } = DateTime.Now;
|
||||
};
|
||||
}
|
||||
[EmailAddress]
|
||||
public string EmailAddress { get; init; }
|
||||
|
||||
public string? TotpSecretkey { get; init; }
|
||||
|
||||
public string Signature => _sha256HexOfMail.Value;
|
||||
|
||||
private readonly Lazy<string> _sha256HexOfMail;
|
||||
|
||||
public DateTime AddedWhen { get; } = DateTime.Now;
|
||||
};
|
||||
Reference in New Issue
Block a user