TekH a3bc26bd08 feat(SaveDocStatusCommand): enhance SaveDocStatusCommandHandler with flexible envelope & receiver filters
- Added support for filtering by Envelope.Id or Envelope.Uuid
- Added support for filtering by Receiver.Id, Receiver.EmailAddress, or Receiver.Signature
- Throw BadRequestException when required identifiers are missing
- Updated repository queries to combine envelope and receiver filters
2025-08-25 15:02:57 +02:00

113 lines
3.2 KiB
C#

using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Domain;
using EnvelopeGenerator.Extensions;
namespace EnvelopeGenerator.Application.DocStatus.Commands;
/// <summary>
///
/// </summary>
public record ModifyDocStatusCommandBase
{
/// <summary>
///
/// </summary>
public string? Key
{
get => Envelope?.Uuid is string uuid && Receiver?.Signature is string signature
? (uuid, signature).EncodeEnvelopeReceiverId()
: null;
init
{
if (value is null)
return;
(string? EnvelopeUuid, string? ReceiverSignature) = value.DecodeEnvelopeReceiverId();
if (string.IsNullOrEmpty(EnvelopeUuid) || string.IsNullOrEmpty(ReceiverSignature))
{
throw new BadRequestException("Der EnvelopeReceiverKey muss ein gültiger Base64-kodierter String sein, der die EnvelopeUuid und die ReceiverSignature enthält.");
}
Envelope.Uuid = EnvelopeUuid;
Receiver.Signature = ReceiverSignature;
}
}
/// <summary>
/// Der Umschlag, der mit dem Empfänger verknüpft ist.
/// </summary>
public EnvelopeQuery Envelope { get; set; } = new();
/// <summary>
/// Der Empfänger, der mit dem Umschlag verknüpft ist.
/// </summary>
public ReceiverQuery Receiver { get; set; } = new();
/// <summary>
/// Gets the current status code.
/// </summary>
public Constants.DocumentStatus Status => Value is null ? Constants.DocumentStatus.Created : Constants.DocumentStatus.Signed;
/// <summary>
/// Gets or sets the display value associated with the status.
/// </summary>
public string? Value { get; set; }
/// <summary>
/// Gets timestamp when this record was added.
/// </summary>
public DateTime StatusChangedWhen { get; } = DateTime.Now;
/// <summary>
/// Maps the current command to a new instance of the specified type.
/// </summary>
/// <typeparam name="TDest"></typeparam>
/// <returns></returns>
public TDest To<TDest>() where TDest : ModifyDocStatusCommandBase, new()
=> new()
{
Key = Key,
Envelope = Envelope,
Receiver = Receiver,
Value = Value
};
}
#region Queries
/// <summary>
/// Repräsentiert eine Abfrage für Umschläge.
/// </summary>
public record EnvelopeQuery
{
/// <summary>
/// Die eindeutige Kennung des Umschlags.
/// </summary>
public int? Id { get; init; }
/// <summary>
/// Die universell eindeutige Kennung des Umschlags.
/// </summary>
public string? Uuid { get; set; }
}
/// <summary>
/// Stellt eine Abfrage dar, um die Details eines Empfängers zu lesen.
/// um spezifische Informationen über einen Empfänger abzurufen.
/// </summary>
public record ReceiverQuery
{
/// <summary>
/// ID des Empfängers
/// </summary>
public int? Id { get; init; }
/// <summary>
/// E-Mail Adresse des Empfängers
/// </summary>
public string? EmailAddress { get; init; }
/// <summary>
/// Eindeutige Signatur des Empfängers
/// </summary>
public string? Signature { get; set; }
}
#endregion