From 996b54463333f3b111aed3a21e0af70a58b89734 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 25 Aug 2025 11:16:57 +0200 Subject: [PATCH] feat(ModifyDocStatusCommandBase): create abstract class to handle common properties of commands --- .../Commands/CreateDocStatusCommand.cs | 14 +++-- .../Commands/ModifyDocStatusCommandBase.cs | 52 +++++++++++++++++++ .../Commands/UpdateDocStatusCommand.cs | 31 ++--------- 3 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 EnvelopeGenerator.Application/DocStatus/Commands/ModifyDocStatusCommandBase.cs diff --git a/EnvelopeGenerator.Application/DocStatus/Commands/CreateDocStatusCommand.cs b/EnvelopeGenerator.Application/DocStatus/Commands/CreateDocStatusCommand.cs index ba7e7dc5..85c0209d 100644 --- a/EnvelopeGenerator.Application/DocStatus/Commands/CreateDocStatusCommand.cs +++ b/EnvelopeGenerator.Application/DocStatus/Commands/CreateDocStatusCommand.cs @@ -1,19 +1,17 @@ -using EnvelopeGenerator.Domain; - -namespace EnvelopeGenerator.Application.DocStatus.Commands; +namespace EnvelopeGenerator.Application.DocStatus.Commands; /// /// /// -public class CreateDocStatusCommand : UpdateDocStatusCommand +public record CreateDocStatusCommand : ModifyDocStatusCommandBase { /// - /// Gets timestamp when this record was added. Returns the current date and time. + /// Gets timestamp when this record was added. Returns null. /// - public DateTime AddedWhen => StatusChangedWhen; + public override DateTime? ChangedWhen => null; /// - /// Gets timestamp when this record was added. Returns the current date and time. + /// Gets timestamp when this record was added. Returns the StatusChangedWhen value. /// - public override DateTime? ChangedWhen { get; } = null; + public DateTime AddedWhen => StatusChangedWhen; } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/DocStatus/Commands/ModifyDocStatusCommandBase.cs b/EnvelopeGenerator.Application/DocStatus/Commands/ModifyDocStatusCommandBase.cs new file mode 100644 index 00000000..6ecc0fe4 --- /dev/null +++ b/EnvelopeGenerator.Application/DocStatus/Commands/ModifyDocStatusCommandBase.cs @@ -0,0 +1,52 @@ +using EnvelopeGenerator.Domain; + +namespace EnvelopeGenerator.Application.DocStatus.Commands; + +/// +/// +/// +public abstract record ModifyDocStatusCommandBase +{ + /// + /// Gets or sets the ID of the associated envelope. + /// + public int EnvelopeId { get; set; } + + /// + /// Gets or sets the ID of the receiver associated with this status. + /// + public int ReceiverId { get; set; } + + /// + /// Gets the current status code. + /// + public Constants.DocumentStatus Status => Value is null ? Constants.DocumentStatus.Created : Constants.DocumentStatus.Signed; + + /// + /// Gets or sets the display value associated with the status. + /// + public string? Value { get; set; } + + /// + /// Gets timestamp when this record was added. + /// + public DateTime StatusChangedWhen { get; } = DateTime.Now; + + /// + /// Gets timestamp when this record was added. + /// + public abstract DateTime? ChangedWhen { get; } + + /// + /// Maps the current command to a new instance of the specified type. + /// + /// + /// + public TDest To() where TDest : ModifyDocStatusCommandBase, new() + => new() + { + EnvelopeId = EnvelopeId, + ReceiverId = ReceiverId, + Value = Value + }; +} diff --git a/EnvelopeGenerator.Application/DocStatus/Commands/UpdateDocStatusCommand.cs b/EnvelopeGenerator.Application/DocStatus/Commands/UpdateDocStatusCommand.cs index 2b024baa..97c5e2b8 100644 --- a/EnvelopeGenerator.Application/DocStatus/Commands/UpdateDocStatusCommand.cs +++ b/EnvelopeGenerator.Application/DocStatus/Commands/UpdateDocStatusCommand.cs @@ -5,35 +5,10 @@ namespace EnvelopeGenerator.Application.DocStatus.Commands; /// /// /// -public class UpdateDocStatusCommand +public record UpdateDocStatusCommand : ModifyDocStatusCommandBase { /// - /// Gets or sets the ID of the associated envelope. + /// Gets timestamp when this record was added. Returns the StatusChangedWhen value. /// - public int EnvelopeId { get; set; } - - /// - /// Gets or sets the ID of the receiver associated with this status. - /// - public int ReceiverId { get; set; } - - /// - /// Gets the current status code. - /// - public Constants.DocumentStatus Status => Value is null ? Constants.DocumentStatus.Created : Constants.DocumentStatus.Signed; - - /// - /// Gets the timestamp when the status was changed. Retrns the AddedWhen value. - /// - public DateTime StatusChangedWhen { get; } = DateTime.Now; - - /// - /// Gets or sets the display value associated with the status. - /// - public string? Value { get; set; } - - /// - /// Gets timestamp when this record was added. Returns the current date and time. - /// - public virtual DateTime? ChangedWhen { get; } = DateTime.Now; + public override DateTime? ChangedWhen => StatusChangedWhen; } \ No newline at end of file