From a3bc26bd08c5bd35c35a4724674845d46168c0e7 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 25 Aug 2025 15:02:57 +0200 Subject: [PATCH] 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 --- .../Commands/ModifyDocStatusCommandBase.cs | 80 +++++++++++++++++-- .../Commands/SaveDocStatusCommand.cs | 24 +++++- .../EnvelopeGenerator.Application.csproj | 2 +- .../Entities/DocumentStatus.cs | 6 ++ .../EnvelopeGenerator.Infrastructure.csproj | 4 +- ...EnvelopeGenerator.Tests.Application.csproj | 2 +- 6 files changed, 103 insertions(+), 15 deletions(-) diff --git a/EnvelopeGenerator.Application/DocStatus/Commands/ModifyDocStatusCommandBase.cs b/EnvelopeGenerator.Application/DocStatus/Commands/ModifyDocStatusCommandBase.cs index 73455e0e..d90fbf05 100644 --- a/EnvelopeGenerator.Application/DocStatus/Commands/ModifyDocStatusCommandBase.cs +++ b/EnvelopeGenerator.Application/DocStatus/Commands/ModifyDocStatusCommandBase.cs @@ -1,4 +1,6 @@ -using EnvelopeGenerator.Domain; +using DigitalData.Core.Exceptions; +using EnvelopeGenerator.Domain; +using EnvelopeGenerator.Extensions; namespace EnvelopeGenerator.Application.DocStatus.Commands; @@ -8,14 +10,37 @@ namespace EnvelopeGenerator.Application.DocStatus.Commands; public record ModifyDocStatusCommandBase { /// - /// Gets or sets the ID of the associated envelope. + /// /// - public int EnvelopeId { get; set; } + 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; + } + } /// - /// Gets or sets the ID of the receiver associated with this status. + /// Der Umschlag, der mit dem Empfänger verknüpft ist. /// - public int ReceiverId { get; set; } + public EnvelopeQuery Envelope { get; set; } = new(); + + /// + /// Der Empfänger, der mit dem Umschlag verknüpft ist. + /// + public ReceiverQuery Receiver { get; set; } = new(); /// /// Gets the current status code. @@ -40,8 +65,49 @@ public record ModifyDocStatusCommandBase public TDest To() where TDest : ModifyDocStatusCommandBase, new() => new() { - EnvelopeId = EnvelopeId, - ReceiverId = ReceiverId, + Key = Key, + Envelope = Envelope, + Receiver = Receiver, Value = Value }; } + +#region Queries +/// +/// Repräsentiert eine Abfrage für Umschläge. +/// +public record EnvelopeQuery +{ + /// + /// Die eindeutige Kennung des Umschlags. + /// + public int? Id { get; init; } + + /// + /// Die universell eindeutige Kennung des Umschlags. + /// + public string? Uuid { get; set; } +} + +/// +/// Stellt eine Abfrage dar, um die Details eines Empfängers zu lesen. +/// um spezifische Informationen über einen Empfänger abzurufen. +/// +public record ReceiverQuery +{ + /// + /// ID des Empfängers + /// + public int? Id { get; init; } + + /// + /// E-Mail Adresse des Empfängers + /// + public string? EmailAddress { get; init; } + + /// + /// Eindeutige Signatur des Empfängers + /// + public string? Signature { get; set; } +} +#endregion \ No newline at end of file diff --git a/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs b/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs index 059991fb..2cd4eb1e 100644 --- a/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs +++ b/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs @@ -1,4 +1,5 @@ using DigitalData.Core.Abstraction.Application.Repository; +using DigitalData.Core.Exceptions; using EnvelopeGenerator.Domain.Entities; using MediatR; using Microsoft.EntityFrameworkCore; @@ -36,15 +37,30 @@ public class SaveDocStatusCommandHandler : IRequestHandler public async Task Handle(SaveDocStatusCommand request, CancellationToken cancel) { - Expression> filter = ds => ds.EnvelopeId == request.EnvelopeId && ds.ReceiverId == request.ReceiverId; + // envelope filter + Expression>? eExp = + request.Envelope.Id is not null + ? ds => ds.EnvelopeId == request.Envelope.Id + : !string.IsNullOrWhiteSpace(request.Envelope.Uuid) + ? ds => ds.Envelope.Uuid == request.Envelope.Uuid + : throw new BadRequestException(); + + // receiver filter + Expression>? rExp = + request.Receiver.Id is not null + ? ds => ds.ReceiverId == request.Receiver.Id + : request.Receiver.EmailAddress is not null + ? ds => ds.Receiver.EmailAddress == request.Receiver.EmailAddress + : !string.IsNullOrWhiteSpace(request.Receiver.Signature) ? ds => ds.Receiver.Signature == request.Receiver.Signature + : throw new BadRequestException(); // ceck if exists - bool isExists = await _repo.ReadOnly().Where(filter).AnyAsync(cancel); + bool isExists = await _repo.ReadOnly().Where(eExp).Where(rExp).AnyAsync(cancel); if (isExists) { var uReq = request.To(); - await _repo.UpdateAsync(uReq, filter, cancel); + await _repo.UpdateAsync(uReq, q => q.Where(eExp).Where(rExp), cancel); } else { @@ -52,7 +68,7 @@ public class SaveDocStatusCommandHandler : IRequestHandler - + diff --git a/EnvelopeGenerator.Domain/Entities/DocumentStatus.cs b/EnvelopeGenerator.Domain/Entities/DocumentStatus.cs index 88b2e24d..3444475f 100644 --- a/EnvelopeGenerator.Domain/Entities/DocumentStatus.cs +++ b/EnvelopeGenerator.Domain/Entities/DocumentStatus.cs @@ -41,6 +41,12 @@ public class DocumentStatus [Column("VALUE", TypeName = "nvarchar(max)")] public string Value { get; set; } + + [ForeignKey("EnvelopeId")] + public virtual Envelope Envelope { get; set; } + + [ForeignKey("ReceiverId")] + public virtual Receiver Receiver { get; set; } } #if NETFRAMEWORK diff --git a/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj b/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj index b4fdf0ea..c03a5d99 100644 --- a/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj +++ b/EnvelopeGenerator.Infrastructure/EnvelopeGenerator.Infrastructure.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/EnvelopeGenerator.Tests.Application/EnvelopeGenerator.Tests.Application.csproj b/EnvelopeGenerator.Tests.Application/EnvelopeGenerator.Tests.Application.csproj index ee2e57b1..cfe0e635 100644 --- a/EnvelopeGenerator.Tests.Application/EnvelopeGenerator.Tests.Application.csproj +++ b/EnvelopeGenerator.Tests.Application/EnvelopeGenerator.Tests.Application.csproj @@ -23,7 +23,7 @@ - +