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
This commit is contained in:
tekh 2025-08-25 15:02:57 +02:00
parent e1f793e571
commit a3bc26bd08
6 changed files with 103 additions and 15 deletions

View File

@ -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
{
/// <summary>
/// Gets or sets the ID of the associated envelope.
///
/// </summary>
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;
}
}
/// <summary>
/// Gets or sets the ID of the receiver associated with this status.
/// Der Umschlag, der mit dem Empfänger verknüpft ist.
/// </summary>
public int ReceiverId { get; set; }
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.
@ -40,8 +65,49 @@ public record ModifyDocStatusCommandBase
public TDest To<TDest>() where TDest : ModifyDocStatusCommandBase, new()
=> new()
{
EnvelopeId = EnvelopeId,
ReceiverId = ReceiverId,
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

View File

@ -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<SaveDocStatusCommand,
/// <returns></returns>
public async Task<int?> Handle(SaveDocStatusCommand request, CancellationToken cancel)
{
Expression<Func<DocumentStatus, bool>> filter = ds => ds.EnvelopeId == request.EnvelopeId && ds.ReceiverId == request.ReceiverId;
// envelope filter
Expression<Func<DocumentStatus, bool>>? 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<Func<DocumentStatus, bool>>? 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<UpdateDocStatusCommand>();
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<SaveDocStatusCommand,
await _repo.CreateAsync(cReq, cancel);
}
var docStatus = await _repo.ReadOnly().Where(filter).FirstOrDefaultAsync(cancel);
var docStatus = await _repo.ReadOnly().Where(eExp).Where(rExp).FirstOrDefaultAsync(cancel);
return docStatus?.Id;
}
}

View File

@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.66" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.1.0" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.2.1" />
<PackageReference Include="DigitalData.Core.Application" Version="3.4.0" />
<PackageReference Include="DigitalData.Core.Client" Version="2.1.0" />
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />

View File

@ -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

View File

@ -8,8 +8,8 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.66" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.1.0" />
<PackageReference Include="DigitalData.Core.Infrastructure" Version="2.2.0" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.2.1" />
<PackageReference Include="DigitalData.Core.Infrastructure" Version="2.3.1" />
<PackageReference Include="DigitalData.Core.Infrastructure.AutoMapper" Version="1.0.3" />
<PackageReference Include="DigitalData.EmailProfilerDispatcher" Version="3.1.1" />
<PackageReference Include="UserManager" Version="1.1.3" />

View File

@ -23,7 +23,7 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.1.0" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.2.1" />
<PackageReference Include="DigitalData.Core.Abstractions" Version="4.0.0" />
<PackageReference Include="DigitalData.Core.API" Version="2.2.1" />
<PackageReference Include="DigitalData.Core.Application" Version="3.4.0" />