- 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`.
36 lines
1.6 KiB
C#
36 lines
1.6 KiB
C#
using Dapper;
|
|
using EnvelopeGenerator.Application.Contracts.Repositories;
|
|
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
|
using EnvelopeGenerator.Application.SQL;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace EnvelopeGenerator.Infrastructure.Executor;
|
|
|
|
public class EnvelopeReceiverExecutor: SQLExecutor, IEnvelopeReceiverExecutor
|
|
{
|
|
private readonly IEnvelopeReceiverRepository _erRepository;
|
|
|
|
public EnvelopeReceiverExecutor(ILogger<EnvelopeExecutor> logger, IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IEnvelopeReceiverRepository erRepository) : base(provider, sqlExecutorParamsOptions)
|
|
{
|
|
_erRepository = erRepository;
|
|
}
|
|
|
|
public async Task<EnvelopeReceiver?> AddEnvelopeReceiverAsync(string envelope_uuid, string emailAddress, string? salutation, string? phone = null, CancellationToken cancellation = default)
|
|
{
|
|
using var connection = new SqlConnection(Params.ConnectionString);
|
|
var sql = Provider.GetRequiredService<EnvelopeReceiverAddReadSQL>();
|
|
await connection.OpenAsync(cancellation);
|
|
var envelopeReceivers = await connection.QueryAsync<EnvelopeReceiver>(sql.Raw, EnvelopeReceiverAddReadSQL.CreateParameters(envelope_uuid, emailAddress, salutation, phone));
|
|
var er = envelopeReceivers.FirstOrDefault();
|
|
|
|
if (er is null)
|
|
return null;
|
|
|
|
return await _erRepository.ReadByIdAsync(envelopeId: er.EnvelopeId, receiverId: er.ReceiverId);
|
|
}
|
|
}
|