- Updated `Extension.cs` to remove old methods and introduce a new parameter creation method. - Modified `IEnvelopeExecutor.cs` to change `CreateEnvelopeAsync` signature for clarity. - Added a consistent `CreateParmas` method in `EnvelopeCreateReadSQL.cs`. - Changed service registration in `DependencyExtensions.cs` from singleton to scoped. - Revised `CreateEnvelopeAsync` in `EnvelopeExecutor.cs` to utilize the new parameter structure and removed user addition logic. These changes enhance code clarity, maintainability, and consistency in parameter handling.
37 lines
1.6 KiB
C#
37 lines
1.6 KiB
C#
using Dapper;
|
|
using DigitalData.UserManager.Application.Contracts.Repositories;
|
|
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 EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
|
|
{
|
|
private readonly IEnvelopeRepository _envelopeRepository;
|
|
|
|
public EnvelopeExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IEnvelopeRepository envelopeRepository) : base(provider, sqlExecutorParamsOptions)
|
|
{
|
|
_envelopeRepository = envelopeRepository;
|
|
}
|
|
|
|
public async Task<Envelope?> CreateEnvelopeAsync(int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default)
|
|
{
|
|
using var connection = new SqlConnection(Params.ConnectionString);
|
|
var sql = Provider.GetRequiredService<EnvelopeCreateReadSQL>();
|
|
await connection.OpenAsync(cancellation);
|
|
var parameters = EnvelopeCreateReadSQL.CreateParmas(userId, title, message, tfaEnabled);
|
|
var envelopes = await connection.QueryAsync<Envelope>(sql.Raw, parameters);
|
|
var envelope = envelopes.FirstOrDefault();
|
|
|
|
if (envelope is null)
|
|
return null;
|
|
|
|
return await _envelopeRepository.ReadByUuidAsync(envelope.Uuid, withAll: true);
|
|
}
|
|
} |