Refactor DTOs for improved structure and documentation

Transitioned from records to classes for flexibility, added XML documentation for clarity, and updated property definitions to use standard getters and setters. Introduced the `required` keyword for essential properties, removed unnecessary constructors, and enhanced property descriptions for better readability. Additionally, overridden `GetHashCode` in `ReceiverReadDto` for proper collection behavior.
This commit is contained in:
Developer 02 2025-05-13 11:05:43 +02:00
parent cc11d70a27
commit 7e66cd4dae
12 changed files with 473 additions and 145 deletions

View File

@ -3,19 +3,45 @@ using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace EnvelopeGenerator.Application.DTOs namespace EnvelopeGenerator.Application.DTOs;
{
/// <summary>
/// Data Transfer Object representing configuration settings.
/// </summary>
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public record ConfigDto( public class ConfigDto : IUnique<int>
string DocumentPath,
int SendingProfile,
string SignatureHost,
string ExternalProgramName,
string ExportPath) : IUnique<int>
{ {
/// <summary>
/// Gets or sets the path to the document.
/// </summary>
public string DocumentPath { get; set; }
/// <summary>
/// Gets or sets the sending profile identifier.
/// </summary>
public int SendingProfile { get; set; }
/// <summary>
/// Gets or sets the signature host URL or name.
/// </summary>
public string SignatureHost { get; set; }
/// <summary>
/// Gets or sets the name of the external program.
/// </summary>
public string ExternalProgramName { get; set; }
/// <summary>
/// Gets or sets the path where exports will be saved.
/// </summary>
public string ExportPath { get; set; }
/// <summary>
/// Gets the ID of the configuration.
/// This DTO represents a single row in the database and does not support an ID.
/// </summary>
[NotMapped] [NotMapped]
[JsonIgnore] [JsonIgnore]
[Obsolete("Configuration does not have an ID; it represents a single table in the database.")] [Obsolete("Configuration does not have an ID; it represents a single table in the database.")]
public int Id => throw new InvalidOperationException("This configuration does not support an ID as it represents a single row in the database."); public int Id => throw new InvalidOperationException("This configuration does not support an ID as it represents a single row in the database.");
};
} }

View File

@ -1,26 +1,96 @@
using DigitalData.Core.Abstractions; using DigitalData.Core.Abstractions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Application.DTOs namespace EnvelopeGenerator.Application.DTOs;
{
/// <summary>
/// Data Transfer Object representing a positioned element assigned to a document receiver.
/// </summary>
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public record DocumentReceiverElementDto( public class DocumentReceiverElementDto : IUnique<int>
int Id, {
int DocumentId, /// <summary>
int ReceiverId, /// Gets or sets the unique identifier of the element.
int ElementType, /// </summary>
double X, public int Id { get; set; }
double Y,
double Width, /// <summary>
double Height, /// Gets or sets the identifier of the associated document.
int Page, /// </summary>
bool Required, public int DocumentId { get; set; }
string? Tooltip,
bool ReadOnly, /// <summary>
int AnnotationIndex, /// Gets or sets the identifier of the receiver.
DateTime AddedWhen, /// </summary>
DateTime? ChangedWhen, public int ReceiverId { get; set; }
double Top,
double Left /// <summary>
): IUnique<int>; /// Gets or sets the type of the element.
/// </summary>
public int ElementType { get; set; }
/// <summary>
/// Gets or sets the X coordinate of the element.
/// </summary>
public double X { get; set; }
/// <summary>
/// Gets or sets the Y coordinate of the element.
/// </summary>
public double Y { get; set; }
/// <summary>
/// Gets or sets the width of the element.
/// </summary>
public double Width { get; set; }
/// <summary>
/// Gets or sets the height of the element.
/// </summary>
public double Height { get; set; }
/// <summary>
/// Gets or sets the page number where the element appears.
/// </summary>
public int Page { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the element is required.
/// </summary>
public bool Required { get; set; }
/// <summary>
/// Gets or sets the tooltip text for the element.
/// </summary>
public string? Tooltip { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the element is read-only.
/// </summary>
public bool ReadOnly { get; set; }
/// <summary>
/// Gets or sets the annotation index for ordering or reference.
/// </summary>
public int AnnotationIndex { get; set; }
/// <summary>
/// Gets or sets the timestamp when the element was added.
/// </summary>
public DateTime AddedWhen { get; set; }
/// <summary>
/// Gets or sets the timestamp when the element was last changed, if applicable.
/// </summary>
public DateTime? ChangedWhen { get; set; }
/// <summary>
/// Gets or sets the top position of the element (in layout terms).
/// </summary>
public double Top { get; set; }
/// <summary>
/// Gets or sets the left position of the element (in layout terms).
/// </summary>
public double Left { get; set; }
} }

View File

@ -1,18 +1,51 @@
using DigitalData.Core.Abstractions; using DigitalData.Core.Abstractions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Application.DTOs namespace EnvelopeGenerator.Application.DTOs;
{
/// <summary>
/// Data Transfer Object representing the status of a document for a specific receiver.
/// </summary>
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public record DocumentStatusDto( public class DocumentStatusDto : IUnique<int>
int Id,
int EnvelopeId,
int ReceiverId,
int Status,
DateTime? StatusChangedWhen,
DateTime AddedWhen,
DateTime? ChangedWhen) : IUnique<int>
{ {
/// <summary>
/// Gets or sets the unique identifier of the document status entry.
/// </summary>
public int Id { get; set; }
/// <summary>
/// Gets or sets the ID of the associated envelope.
/// </summary>
public int EnvelopeId { get; set; }
/// <summary>
/// Gets or sets the ID of the receiver associated with this status.
/// </summary>
public int ReceiverId { get; set; }
/// <summary>
/// Gets or sets the current status code.
/// </summary>
public int Status { get; set; }
/// <summary>
/// Gets or sets the timestamp when the status was changed.
/// </summary>
public DateTime? StatusChangedWhen { get; set; }
/// <summary>
/// Gets or sets the timestamp when this record was added.
/// </summary>
public DateTime AddedWhen { get; set; }
/// <summary>
/// Gets or sets the timestamp when this record was last changed.
/// </summary>
public DateTime? ChangedWhen { get; set; }
/// <summary>
/// Gets or sets the display value associated with the status.
/// </summary>
public string? Value { get; set; } public string? Value { get; set; }
};
} }

View File

@ -1,16 +1,51 @@
using DigitalData.Core.Abstractions; using DigitalData.Core.Abstractions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Application.DTOs namespace EnvelopeGenerator.Application.DTOs;
{
/// <summary>
/// Data Transfer Object representing certificate information for an envelope.
/// </summary>
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public record EnvelopeCertificateDto( public class EnvelopeCertificateDto : IUnique<int>
int Id, {
int EnvelopeId, /// <summary>
string EnvelopeUuid, /// Gets the unique identifier of the certificate.
string EnvelopeSubject, /// </summary>
int CreatorId, public int Id { get; init; }
string CreatorName,
string CreatorEmail, /// <summary>
int EnvelopeStatus) : IUnique<int>; /// Gets the envelope ID associated with the certificate.
/// </summary>
public int EnvelopeId { get; init; }
/// <summary>
/// Gets the UUID of the envelope.
/// </summary>
public string EnvelopeUuid { get; init; }
/// <summary>
/// Gets the subject of the envelope.
/// </summary>
public string EnvelopeSubject { get; init; }
/// <summary>
/// Gets the ID of the creator of the envelope.
/// </summary>
public int CreatorId { get; init; }
/// <summary>
/// Gets the name of the creator.
/// </summary>
public string CreatorName { get; init; }
/// <summary>
/// Gets the email address of the creator.
/// </summary>
public string CreatorEmail { get; init; }
/// <summary>
/// Gets the current status of the envelope.
/// </summary>
public int EnvelopeStatus { get; init; }
} }

View File

@ -1,15 +1,36 @@
using DigitalData.Core.Abstractions; using DigitalData.Core.Abstractions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Application.DTOs namespace EnvelopeGenerator.Application.DTOs;
{
/// <summary>
/// Data Transfer Object representing a document within an envelope, including optional binary data and form elements.
/// </summary>
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public record EnvelopeDocumentDto public class EnvelopeDocumentDto : IUnique<int>
( {
int Id, /// <summary>
int EnvelopeId, /// Gets or sets the unique identifier of the document.
DateTime AddedWhen, /// </summary>
byte[]? ByteData = null, public int Id { get; set; }
IEnumerable<DocumentReceiverElementDto>? Elements = null
) : IUnique<int>; /// <summary>
/// Gets or sets the envelope ID to which the document belongs.
/// </summary>
public int EnvelopeId { get; set; }
/// <summary>
/// Gets or sets the date and time when the document was added.
/// </summary>
public DateTime AddedWhen { get; set; }
/// <summary>
/// Gets or sets the binary data of the document, if available.
/// </summary>
public byte[]? ByteData { get; set; }
/// <summary>
/// Gets or sets the collection of elements associated with the document for receiver interactions, if any.
/// </summary>
public IEnumerable<DocumentReceiverElementDto>? Elements { get; set; }
} }

View File

@ -4,10 +4,10 @@ using DigitalData.UserManager.Application.DTOs.User;
using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Domain.Entities;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Application.DTOs namespace EnvelopeGenerator.Application.DTOs;
{
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public record EnvelopeDto() : IUnique<int> public record EnvelopeDto : IUnique<int>
{ {
public int Id { get; set; } public int Id { get; set; }
@ -53,4 +53,3 @@ namespace EnvelopeGenerator.Application.DTOs
public IEnumerable<EnvelopeDocumentDto>? Documents { get; set; } public IEnumerable<EnvelopeDocumentDto>? Documents { get; set; }
} }
}

View File

@ -1,12 +1,34 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Application.DTOs.EnvelopeHistory namespace EnvelopeGenerator.Application.DTOs.EnvelopeHistory;
/// <summary>
/// Data Transfer Object for creating a new envelope history record.
/// </summary>
public class EnvelopeHistoryCreateDto
{ {
[ApiExplorerSettings(IgnoreApi = true)] /// <summary>
public record EnvelopeHistoryCreateDto( /// Gets or sets the identifier of the envelope.
int EnvelopeId, /// </summary>
string UserReference, public int EnvelopeId { get; set; }
int Status,
DateTime? ActionDate, /// <summary>
string? Comment = null); /// Gets or sets the user reference associated with the action.
/// </summary>
public required string UserReference { get; set; }
/// <summary>
/// Gets or sets the status of the envelope at the time of the action.
/// </summary>
public int Status { get; set; }
/// <summary>
/// Gets or sets the date and time when the action occurred.
/// </summary>
public DateTime? ActionDate { get; set; }
/// <summary>
/// Gets or sets an optional comment related to the action.
/// </summary>
public string? Comment { get; set; }
} }

View File

@ -1,23 +1,86 @@
using DigitalData.Core.Abstractions; using DigitalData.Core.Abstractions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Application.DTOs namespace EnvelopeGenerator.Application.DTOs;
{
/// <summary>
/// Data Transfer Object representing a type of envelope with its configuration settings.
/// </summary>
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public record EnvelopeTypeDto( public class EnvelopeTypeDto : IUnique<int>
int Id, {
string Title, /// <summary>
string Language, /// Gets or sets the unique identifier of the envelope type.
int? ExpiresDays, /// </summary>
int? CertificationType, public int Id { get; set; }
bool? UseAccessCode,
int? FinalEmailToCreator, /// <summary>
int? FinalEmailToReceivers, /// Gets or sets the title of the envelope type.
DateTime AddedWhen, /// </summary>
DateTime? ChangedWhen, public string Title { get; set; }
int? ExpiresWarningDays,
bool? SendReminderEmails, /// <summary>
int? FirstReminderDays, /// Gets or sets the language code used in this envelope type.
int? ReminderIntervalDays, /// </summary>
int? ContractType) : IUnique<int>; public string Language { get; set; }
/// <summary>
/// Gets or sets the number of days after which the envelope expires.
/// </summary>
public int? ExpiresDays { get; set; }
/// <summary>
/// Gets or sets the certification type identifier.
/// </summary>
public int? CertificationType { get; set; }
/// <summary>
/// Gets or sets a value indicating whether an access code is required.
/// </summary>
public bool? UseAccessCode { get; set; }
/// <summary>
/// Gets or sets the final email template ID to be sent to the creator.
/// </summary>
public int? FinalEmailToCreator { get; set; }
/// <summary>
/// Gets or sets the final email template ID to be sent to the receivers.
/// </summary>
public int? FinalEmailToReceivers { get; set; }
/// <summary>
/// Gets or sets the timestamp when this envelope type was added.
/// </summary>
public DateTime AddedWhen { get; set; }
/// <summary>
/// Gets or sets the timestamp when this envelope type was last changed.
/// </summary>
public DateTime? ChangedWhen { get; set; }
/// <summary>
/// Gets or sets the number of days before expiry when a warning should be sent.
/// </summary>
public int? ExpiresWarningDays { get; set; }
/// <summary>
/// Gets or sets a value indicating whether reminder emails should be sent.
/// </summary>
public bool? SendReminderEmails { get; set; }
/// <summary>
/// Gets or sets the number of days before the first reminder is sent.
/// </summary>
public int? FirstReminderDays { get; set; }
/// <summary>
/// Gets or sets the interval in days between reminder emails.
/// </summary>
public int? ReminderIntervalDays { get; set; }
/// <summary>
/// Gets or sets the contract type associated with the envelope type.
/// </summary>
public int? ContractType { get; set; }
} }

View File

@ -20,7 +20,7 @@ public record ReceiverCreateDto
} }
[EmailAddress] [EmailAddress]
public string EmailAddress { get; init; } public required string EmailAddress { get; init; }
public string? TotpSecretkey { get; init; } public string? TotpSecretkey { get; init; }

View File

@ -1,5 +1,4 @@
using DigitalData.Core.Abstractions; using DigitalData.Core.Abstractions;
using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver; using EnvelopeGenerator.Application.DTOs.EnvelopeReceiver;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@ -7,19 +6,27 @@ using System.Text.Json.Serialization;
namespace EnvelopeGenerator.Application.DTOs.Receiver; namespace EnvelopeGenerator.Application.DTOs.Receiver;
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public record ReceiverReadDto( public class ReceiverReadDto : IUnique<int>
int Id,
string EmailAddress,
string Signature,
DateTime AddedWhen
) : BaseDTO<int>(Id), IUnique<int>
{ {
public int Id { get; set; }
public string EmailAddress { get; set; }
public string Signature { get; set; }
public DateTime AddedWhen { get; set; }
[JsonIgnore] [JsonIgnore]
public IEnumerable<EnvelopeReceiverBasicDto>? EnvelopeReceivers { get; init; } public IEnumerable<EnvelopeReceiverBasicDto>? EnvelopeReceivers { get; set; }
public string? LastUsedName => EnvelopeReceivers?.LastOrDefault()?.Name; public string? LastUsedName => EnvelopeReceivers?.LastOrDefault()?.Name;
public string? TotpSecretkey { get; set; } = null; public string? TotpSecretkey { get; set; } = null;
public DateTime? TfaRegDeadline { get; set; } public DateTime? TfaRegDeadline { get; set; }
};
public override int GetHashCode()
{
return Id.GetHashCode();
}
}

View File

@ -3,5 +3,26 @@ using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Application.DTOs.Receiver; namespace EnvelopeGenerator.Application.DTOs.Receiver;
/// <summary>
/// Data Transfer Object for updating a receiver's information.
/// </summary>
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public record ReceiverUpdateDto(int Id, string? TotpSecretkey = null, DateTime? TfaRegDeadline = null) : IUnique<int>; public class ReceiverUpdateDto : IUnique<int>
{
/// <summary>
/// Gets or sets the unique identifier of the receiver.
/// </summary>
public int Id { get; set; }
/// <summary>
/// Gets or sets the TOTP (Time-based One-Time Password) secret key.
/// Optional.
/// </summary>
public string? TotpSecretkey { get; set; }
/// <summary>
/// Gets or sets the deadline for two-factor authentication registration.
/// Optional.
/// </summary>
public DateTime? TfaRegDeadline { get; set; }
}

View File

@ -1,15 +1,46 @@
using DigitalData.Core.Abstractions; using DigitalData.Core.Abstractions;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.Application.DTOs namespace EnvelopeGenerator.Application.DTOs;
{
/// <summary>
/// Data Transfer Object representing a user receiver with associated details.
/// </summary>
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public record UserReceiverDto( public class UserReceiverDto : IUnique<int>
int Id, {
int UserId, /// <summary>
int ReceiverId, /// Gets or sets the unique identifier of the user receiver.
string Name, /// </summary>
string CompanyName, public int Id { get; set; }
string JobTitle,
DateTime AddedWhen) : IUnique<int>; /// <summary>
/// Gets or sets the identifier of the user associated with the receiver.
/// </summary>
public int UserId { get; set; }
/// <summary>
/// Gets or sets the identifier of the receiver.
/// </summary>
public int ReceiverId { get; set; }
/// <summary>
/// Gets or sets the name of the receiver.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets or sets the company name of the receiver.
/// </summary>
public string CompanyName { get; set; }
/// <summary>
/// Gets or sets the job title of the receiver.
/// </summary>
public string JobTitle { get; set; }
/// <summary>
/// Gets or sets the timestamp when the user receiver was added.
/// </summary>
public DateTime AddedWhen { get; set; }
} }