Refactor envelope and receiver methods for clarity

- Changed return type of `CreateEnvelopeAsync` to ensure a non-null `Envelope` is always returned.
- Updated `AddEnvelopeReceiverAsync` to allow nullable `salutation` parameter.
- Renamed cancellation token parameter in `CreateEnvelopeReceiverCommandHandler` for consistency.
- Enhanced error handling in `CreateEnvelopeAsync` to throw exceptions on failure with improved messages.
- Adjusted `CreateParameters` method to accept nullable `salutation`.
This commit is contained in:
Developer 02
2025-05-06 12:05:24 +02:00
parent b5b9155bc0
commit 8c2550ff1d
6 changed files with 31 additions and 14 deletions

View File

@@ -17,5 +17,5 @@ public interface IEnvelopeExecutor : ISQLExecutor
/// <param name="tfaEnabled"></param>
/// <param name="cancellation"></param>
/// <returns></returns>
Task<Envelope?> CreateEnvelopeAsync(int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default);
Task<Envelope> CreateEnvelopeAsync(int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default);
}

View File

@@ -16,5 +16,5 @@ public interface IEnvelopeReceiverExecutor
/// <param name="phone"></param>
/// <param name="cancellation"></param>
/// <returns></returns>
Task<EnvelopeReceiver?> AddEnvelopeReceiverAsync(string envelope_uuid, string emailAddress, string salutation, string? phone = null, CancellationToken cancellation = default);
Task<EnvelopeReceiver?> AddEnvelopeReceiverAsync(string envelope_uuid, string emailAddress, string? salutation = null, string? phone = null, CancellationToken cancellation = default);
}

View File

@@ -1,4 +1,5 @@
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
using EnvelopeGenerator.Domain.Entities;
using MediatR;
namespace EnvelopeGenerator.Application.EnvelopeReceivers.Commands.Create;
@@ -31,10 +32,25 @@ public class CreateEnvelopeReceiverCommandHandler : IRequestHandler<CreateEnvelo
/// and storing the envelope and document details.
/// </summary>
/// <param name="request">The command containing all necessary information to create an envelope.</param>
/// <param name="cancellationToken">Token to observe while waiting for the task to complete.</param>
/// <param name="cancel">Token to observe while waiting for the task to complete.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public Task Handle(CreateEnvelopeReceiverCommand request, CancellationToken cancellationToken)
public async Task Handle(CreateEnvelopeReceiverCommand request, CancellationToken cancel)
{
throw new NotImplementedException();
int userId = request.UserId ?? throw new InvalidOperationException("UserId cannot be null when creating an envelope.");
var envelope = await _envelopeExecutor.CreateEnvelopeAsync(userId, request.Title, request.Message, request.TFAEnabled, cancel);
List<EnvelopeReceiver> sentRecipients = new();
List<ReceiverGetOrCreateCommand> unsentRecipients = new();
foreach (var receiver in request.Receivers)
{
var envelopeReceiver = await _erExecutor.AddEnvelopeReceiverAsync(envelope.Uuid, receiver.EmailAddress, receiver.Salution, receiver.PhoneNumber, cancel);
if (envelopeReceiver is null)
unsentRecipients.Add(receiver);
else
sentRecipients.Add(envelopeReceiver);
}
}
}

View File

@@ -40,7 +40,7 @@ public class EnvelopeReceiverAddReadSQL : ISQL<Envelope>
/// <param name="salutation"></param>
/// <param name="phone"></param>
/// <returns></returns>
public static DynamicParameters CreateParameters(string envelope_uuid, string emailAddress, string salutation, string? phone = null)
public static DynamicParameters CreateParameters(string envelope_uuid, string emailAddress, string? salutation = null, string? phone = null)
{
var parameters = new DynamicParameters();
parameters.Add("@ENV_UID", envelope_uuid);