Refactor envelope creation methods and parameter handling
- 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.
This commit is contained in:
@@ -82,8 +82,8 @@ public static class DIExtensions
|
||||
SetDapperTypeMap<DocumentReceiverElement>();
|
||||
SetDapperTypeMap<DocumentStatus>();
|
||||
|
||||
services.AddSingleton<IEnvelopeExecutor, EnvelopeExecutor>();
|
||||
services.AddSingleton<IEnvelopeReceiverExecutor, EnvelopeReceiverExecutor>();
|
||||
services.AddScoped<IEnvelopeExecutor, EnvelopeExecutor>();
|
||||
services.AddScoped<IEnvelopeReceiverExecutor, EnvelopeReceiverExecutor>();
|
||||
|
||||
if (sqlExecutorConfiguration is not null || sqlExecutorConfigureOptions is not null)
|
||||
services.AddSQLExecutor(sqlExecutorConfiguration, sqlExecutorConfigureOptions);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -12,31 +13,25 @@ namespace EnvelopeGenerator.Infrastructure.Executor;
|
||||
|
||||
public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IEnvelopeRepository _envelopeRepository;
|
||||
|
||||
public EnvelopeExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IUserRepository userRepository) : base(provider, sqlExecutorParamsOptions)
|
||||
public EnvelopeExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IEnvelopeRepository envelopeRepository) : base(provider, sqlExecutorParamsOptions)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_envelopeRepository = envelopeRepository;
|
||||
}
|
||||
|
||||
public async Task<Envelope?> CreateEnvelopeAsync(DynamicParameters parameters, bool addUser = true, CancellationToken cancellation = default)
|
||||
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;
|
||||
|
||||
// Add User
|
||||
if (addUser)
|
||||
{
|
||||
var user = await _userRepository.ReadByIdAsync(envelope.UserId);
|
||||
envelope.User = user;
|
||||
}
|
||||
|
||||
return envelope;
|
||||
return await _envelopeRepository.ReadByUuidAsync(envelope.Uuid, withAll: true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user