Updated `CreateEnvelopeReceiverResponse` and `EnvelopeReceiverController` to rename `SentRecipients` to `SentReceiver` and `UnsentRecipients` to `UnsentReceivers`. Adjusted corresponding lists and mappings to ensure uniformity in naming conventions across the codebase.
68 lines
2.9 KiB
C#
68 lines
2.9 KiB
C#
using AutoMapper;
|
|
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
|
using EnvelopeGenerator.Application.DTOs.Receiver;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.EnvelopeReceivers.Commands.Create;
|
|
|
|
/// <summary>
|
|
/// Handles the creation of an envelope along with its associated document and recipients.
|
|
/// This command processes the envelope data, including title, message, document content,
|
|
/// recipient list, and optional two-factor authentication settings.
|
|
/// </summary>
|
|
public class CreateEnvelopeReceiverCommandHandler : IRequestHandler<CreateEnvelopeReceiverCommand, CreateEnvelopeReceiverResponse>
|
|
{
|
|
private readonly IMapper _mapper;
|
|
|
|
private readonly IEnvelopeExecutor _envelopeExecutor;
|
|
|
|
private readonly IEnvelopeReceiverExecutor _erExecutor;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="mapper"></param>
|
|
/// <param name="envelopeExecutor"></param>
|
|
/// <param name="erExecutor"></param>
|
|
public CreateEnvelopeReceiverCommandHandler(IMapper mapper, IEnvelopeExecutor envelopeExecutor, IEnvelopeReceiverExecutor erExecutor)
|
|
{
|
|
_mapper = mapper;
|
|
_envelopeExecutor = envelopeExecutor;
|
|
_erExecutor = erExecutor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles the execution of the <see cref="CreateEnvelopeReceiverCommand"/>.
|
|
/// Responsible for validating input data, creating or retrieving recipients, associating signatures,
|
|
/// and storing the envelope and document details.
|
|
/// </summary>
|
|
/// <param name="request">The command containing all necessary information to create an envelope.</param>
|
|
/// <param name="cancel">Token to observe while waiting for the task to complete.</param>
|
|
/// <returns>A task representing the asynchronous operation.</returns>
|
|
public async Task<CreateEnvelopeReceiverResponse> Handle(CreateEnvelopeReceiverCommand request, CancellationToken cancel)
|
|
{
|
|
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);
|
|
}
|
|
|
|
var res = _mapper.Map<CreateEnvelopeReceiverResponse>(envelope);
|
|
res.UnsentReceivers = unsentRecipients;
|
|
res.SentReceiver = _mapper.Map<IEnumerable<ReceiverReadDto>>(sentRecipients);
|
|
return res;
|
|
}
|
|
}
|