From f558d03bdf18afaa96033508752307b18bd6c4da Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 2 Oct 2026 10:55:09 +0200 Subject: [PATCH] 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. --- .../Common/Dto/DocumentDetailsDto.cs | 27 +++++++++++++++++ .../Common/Dto/DocumentDto.cs | 29 ++++++++----------- 2 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 EnvelopeGenerator.Application/Common/Dto/DocumentDetailsDto.cs diff --git a/EnvelopeGenerator.Application/Common/Dto/DocumentDetailsDto.cs b/EnvelopeGenerator.Application/Common/Dto/DocumentDetailsDto.cs new file mode 100644 index 00000000..5e3a6fd4 --- /dev/null +++ b/EnvelopeGenerator.Application/Common/Dto/DocumentDetailsDto.cs @@ -0,0 +1,27 @@ +namespace EnvelopeGenerator.Application.Common.Dto; + +/// +/// Data Transfer Object representing document metadata and elements without binary payload. +/// +public record DocumentDetailsDto +{ + /// + /// Gets or sets the unique identifier of the document. + /// + public int Id { get; init; } + + /// + /// Gets or sets the envelope ID to which the document belongs. + /// + public int EnvelopeId { get; init; } + + /// + /// Gets or sets the date and time when the document was added. + /// + public DateTime AddedWhen { get; init; } + + /// + /// Gets or sets the collection of elements associated with the document for receiver interactions, if any. + /// + public IEnumerable? Elements { get; init; } +} diff --git a/EnvelopeGenerator.Application/Common/Dto/DocumentDto.cs b/EnvelopeGenerator.Application/Common/Dto/DocumentDto.cs index 34403d8f..e8bb7c02 100644 --- a/EnvelopeGenerator.Application/Common/Dto/DocumentDto.cs +++ b/EnvelopeGenerator.Application/Common/Dto/DocumentDto.cs @@ -3,30 +3,25 @@ /// /// Data Transfer Object representing a document within an envelope, including optional binary data and form elements. /// -public class DocumentDto +public record DocumentDto : DocumentDetailsDto { /// - /// Gets or sets the unique identifier of the document. + /// /// - public int Id { get; set; } + public DocumentDto() { } /// - /// Gets or sets the envelope ID to which the document belongs. + /// /// - public int EnvelopeId { get; set; } - - /// - /// Gets or sets the date and time when the document was added. - /// - public DateTime AddedWhen { get; set; } + /// + /// + public DocumentDto(byte[] byteData, DocumentDetailsDto details) : base(details) + { + ByteData = byteData; + } /// /// Gets or sets the binary data of the document, if available. /// - public byte[]? ByteData { get; set; } - - /// - /// Gets or sets the collection of elements associated with the document for receiver interactions, if any. - /// - public IEnumerable? Elements { get; set; } -} \ No newline at end of file + public byte[]? ByteData { get; init; } +}