refactor(EnvelopeReceiverQueryBase): simplify EnvelopeReceiverQueryBase.Key handling

- Introduced private backing field `_key` for Key property
- Removed dynamic recomputation from Envelope and Receiver
- Ensured Key is only set once during initialization
- Improved null handling and exception safety
This commit is contained in:
Developer 02 2025-08-26 16:49:22 +02:00
parent c887f857cd
commit 2355a566e4

View File

@ -17,24 +17,26 @@ public record EnvelopeReceiverQueryBase<TEnvelopeQuery, TReceiverQuery>
where TEnvelopeQuery : EnvelopeQueryBase, new() where TEnvelopeQuery : EnvelopeQueryBase, new()
where TReceiverQuery : ReceiverQueryBase, new() where TReceiverQuery : ReceiverQueryBase, new()
{ {
private string? _key;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public virtual string? Key public virtual string? Key
{ {
get => Envelope?.Uuid is string uuid && Receiver?.Signature is string signature get => _key;
? (uuid, signature).EncodeEnvelopeReceiverId()
: null;
init init
{ {
if (value is null) if (value is null)
{
_key = null;
return; return;
}
(string? EnvelopeUuid, string? ReceiverSignature) = value.DecodeEnvelopeReceiverId(); (string? EnvelopeUuid, string? ReceiverSignature) = value.DecodeEnvelopeReceiverId();
if (string.IsNullOrEmpty(EnvelopeUuid) || string.IsNullOrEmpty(ReceiverSignature)) 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."); throw new BadRequestException("Der EnvelopeReceiverKey muss ein gültiger Base64-kodierter String sein, der die EnvelopeUuid und die ReceiverSignature enthält.");
}
Envelope = new TEnvelopeQuery() Envelope = new TEnvelopeQuery()
{ {
Uuid = EnvelopeUuid Uuid = EnvelopeUuid
@ -43,6 +45,7 @@ public record EnvelopeReceiverQueryBase<TEnvelopeQuery, TReceiverQuery>
{ {
Signature = ReceiverSignature Signature = ReceiverSignature
}; };
_key = value;
} }
} }