Refactor DocumentDto to use DocumentDetailsDto

Introduce a new `DocumentDetailsDto` record to encapsulate shared document metadata and elements without binary payload. Refactor `DocumentDto` to inherit from `DocumentDetailsDto`, eliminating redundant properties and improving code reuse.

Convert `DocumentDto` from a class to a record for immutability. Add a parameterized constructor to `DocumentDto` for initializing binary data alongside metadata. Update `ByteData` to use the `init` accessor.

These changes enhance maintainability, reduce duplication, and enforce immutability by leveraging C# records and inheritance.
This commit is contained in:
2026-10-02 10:55:09 +02:00
parent db79053c62
commit f558d03bdf
2 changed files with 39 additions and 17 deletions

View File

@@ -0,0 +1,27 @@
namespace EnvelopeGenerator.Application.Common.Dto;
/// <summary>
/// Data Transfer Object representing document metadata and elements without binary payload.
/// </summary>
public record DocumentDetailsDto
{
/// <summary>
/// Gets or sets the unique identifier of the document.
/// </summary>
public int Id { get; init; }
/// <summary>
/// Gets or sets the envelope ID to which the document belongs.
/// </summary>
public int EnvelopeId { get; init; }
/// <summary>
/// Gets or sets the date and time when the document was added.
/// </summary>
public DateTime AddedWhen { get; init; }
/// <summary>
/// Gets or sets the collection of elements associated with the document for receiver interactions, if any.
/// </summary>
public IEnumerable<DocReceiverElementDto>? Elements { get; init; }
}

View File

@@ -3,30 +3,25 @@
/// <summary> /// <summary>
/// Data Transfer Object representing a document within an envelope, including optional binary data and form elements. /// Data Transfer Object representing a document within an envelope, including optional binary data and form elements.
/// </summary> /// </summary>
public class DocumentDto public record DocumentDto : DocumentDetailsDto
{ {
/// <summary> /// <summary>
/// Gets or sets the unique identifier of the document. ///
/// </summary> /// </summary>
public int Id { get; set; } public DocumentDto() { }
/// <summary> /// <summary>
/// Gets or sets the envelope ID to which the document belongs. ///
/// </summary> /// </summary>
public int EnvelopeId { get; set; } /// <param name="byteData"></param>
/// <param name="details"></param>
/// <summary> public DocumentDto(byte[] byteData, DocumentDetailsDto details) : base(details)
/// Gets or sets the date and time when the document was added. {
/// </summary> ByteData = byteData;
public DateTime AddedWhen { get; set; } }
/// <summary> /// <summary>
/// Gets or sets the binary data of the document, if available. /// Gets or sets the binary data of the document, if available.
/// </summary> /// </summary>
public byte[]? ByteData { get; set; } public byte[]? ByteData { get; init; }
}
/// <summary>
/// Gets or sets the collection of elements associated with the document for receiver interactions, if any.
/// </summary>
public IEnumerable<DocReceiverElementDto>? Elements { get; set; }
}