diff --git a/EnvelopeGenerator.Application/Contracts/SQLExecutor/Extension.cs b/EnvelopeGenerator.Application/Contracts/SQLExecutor/Extension.cs deleted file mode 100644 index e0a49e98..00000000 --- a/EnvelopeGenerator.Application/Contracts/SQLExecutor/Extension.cs +++ /dev/null @@ -1,80 +0,0 @@ -using Dapper; -using EnvelopeGenerator.Application.SQL; -using EnvelopeGenerator.Domain.Entities; - -namespace EnvelopeGenerator.Application.Contracts.SQLExecutor; - -/// -/// -/// -public static class Extension -{ - private static DynamicParameters CreateParmas(int userId, string title = "", string message = "", bool tfaEnabled = false) - { - var parameters = new DynamicParameters(); - parameters.Add("@UserId", userId); - parameters.Add("@Title", title); - parameters.Add("@TfaEnabled", tfaEnabled ? 1 : 0); - parameters.Add("@Message", message); - return parameters; - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static async Task CreateEnvelopeAsync(this ISQLExecutor executor, int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default) - where TEntity : class - { - var parameters = CreateParmas(userId, title, message, tfaEnabled); - - var envelopes = await executor.Execute(parameters, cancellation); - return envelopes.FirstOrDefault(); - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static async Task CreateEnvelopeAsync(this IEnvelopeExecutor executor, int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default) - { - var parameters = CreateParmas(userId, title, message, tfaEnabled); - - return await executor.CreateEnvelopeAsync(parameters, cancellation: cancellation); - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static async Task AddEnvelopeReceiver(this ISQLExecutor executor, string envelope_uuid, string emailAdress, string salutation, string? phone = null, CancellationToken cancellation = default) - { - var parameters = new DynamicParameters(); - parameters.Add("@ENV_UID", envelope_uuid); - parameters.Add("@EMAIL_ADRESS", emailAdress); - parameters.Add("@SALUTATION", salutation); - parameters.Add("@PHONE", phone); - - var envelopeReceivers = await executor.Execute(parameters, cancellation); - return envelopeReceivers.FirstOrDefault(); - } -} \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Contracts/SQLExecutor/IEnvelopeExecutor.cs b/EnvelopeGenerator.Application/Contracts/SQLExecutor/IEnvelopeExecutor.cs index f197cadf..f5b639c8 100644 --- a/EnvelopeGenerator.Application/Contracts/SQLExecutor/IEnvelopeExecutor.cs +++ b/EnvelopeGenerator.Application/Contracts/SQLExecutor/IEnvelopeExecutor.cs @@ -11,9 +11,11 @@ public interface IEnvelopeExecutor : ISQLExecutor /// /// /// - /// - /// + /// + /// + /// + /// /// /// - Task CreateEnvelopeAsync(DynamicParameters parameters, bool addUser = true, CancellationToken cancellation = default); + Task CreateEnvelopeAsync(int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default); } diff --git a/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs b/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs index 9dc83fde..449eb9d2 100644 --- a/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs +++ b/EnvelopeGenerator.Application/SQL/EnvelopeCreateReadSQL.cs @@ -1,4 +1,5 @@ -using EnvelopeGenerator.Application.Contracts.SQLExecutor; +using Dapper; +using EnvelopeGenerator.Application.Contracts.SQLExecutor; using EnvelopeGenerator.Domain.Entities; namespace EnvelopeGenerator.Application.SQL; @@ -26,4 +27,22 @@ public class EnvelopeCreateReadSQL : ISQL FROM [dbo].[TBSIG_ENVELOPE] WHERE [ENVELOPE_UUID] = @OUT_UID; "; + + /// + /// + /// + /// + /// + /// + /// + /// + public static DynamicParameters CreateParmas(int userId, string title = "", string message = "", bool tfaEnabled = false) + { + var parameters = new DynamicParameters(); + parameters.Add("@UserId", userId); + parameters.Add("@Title", title); + parameters.Add("@TfaEnabled", tfaEnabled ? 1 : 0); + parameters.Add("@Message", message); + return parameters; + } } \ No newline at end of file diff --git a/EnvelopeGenerator.Infrastructure/DependencyExtensions.cs b/EnvelopeGenerator.Infrastructure/DependencyExtensions.cs index 90a3dbc6..dd5fd895 100644 --- a/EnvelopeGenerator.Infrastructure/DependencyExtensions.cs +++ b/EnvelopeGenerator.Infrastructure/DependencyExtensions.cs @@ -82,8 +82,8 @@ public static class DIExtensions SetDapperTypeMap(); SetDapperTypeMap(); - services.AddSingleton(); - services.AddSingleton(); + services.AddScoped(); + services.AddScoped(); if (sqlExecutorConfiguration is not null || sqlExecutorConfigureOptions is not null) services.AddSQLExecutor(sqlExecutorConfiguration, sqlExecutorConfigureOptions); diff --git a/EnvelopeGenerator.Infrastructure/Executor/EnvelopeExecutor.cs b/EnvelopeGenerator.Infrastructure/Executor/EnvelopeExecutor.cs index 9b16ec1e..b1bf792d 100644 --- a/EnvelopeGenerator.Infrastructure/Executor/EnvelopeExecutor.cs +++ b/EnvelopeGenerator.Infrastructure/Executor/EnvelopeExecutor.cs @@ -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 sqlExecutorParamsOptions, IUserRepository userRepository) : base(provider, sqlExecutorParamsOptions) + public EnvelopeExecutor(IServiceProvider provider, IOptions sqlExecutorParamsOptions, IEnvelopeRepository envelopeRepository) : base(provider, sqlExecutorParamsOptions) { - _userRepository = userRepository; + _envelopeRepository = envelopeRepository; } - public async Task CreateEnvelopeAsync(DynamicParameters parameters, bool addUser = true, CancellationToken cancellation = default) + public async Task CreateEnvelopeAsync(int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default) { using var connection = new SqlConnection(Params.ConnectionString); var sql = Provider.GetRequiredService(); await connection.OpenAsync(cancellation); + var parameters = EnvelopeCreateReadSQL.CreateParmas(userId, title, message, tfaEnabled); var envelopes = await connection.QueryAsync(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); } } \ No newline at end of file