Refactor EnvelopeExecutor to use IUserRepository

Updated the EnvelopeExecutor class to replace the IEnvelopeRepository dependency with IUserRepository. Modified the constructor and adjusted the CreateEnvelopeAsync method to return the envelope with associated user information instead of retrieving it from the repository.
This commit is contained in:
Developer 02 2025-05-06 14:53:23 +02:00
parent eaa1232490
commit cae00d9177

View File

@ -6,18 +6,17 @@ using EnvelopeGenerator.Application.SQL;
using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Domain.Entities;
using Microsoft.Data.SqlClient; using Microsoft.Data.SqlClient;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace EnvelopeGenerator.Infrastructure.Executor; namespace EnvelopeGenerator.Infrastructure.Executor;
public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
{ {
private readonly IEnvelopeRepository _envelopeRepository; private readonly IUserRepository _userRepository;
public EnvelopeExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IEnvelopeRepository envelopeRepository) : base(provider, sqlExecutorParamsOptions) public EnvelopeExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IUserRepository userRepository) : base(provider, sqlExecutorParamsOptions)
{ {
_envelopeRepository = envelopeRepository; _userRepository = userRepository;
} }
public async Task<Envelope> CreateEnvelopeAsync(int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default) public async Task<Envelope> CreateEnvelopeAsync(int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default)
@ -30,9 +29,9 @@ public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
var envelope = envelopes.FirstOrDefault() var envelope = envelopes.FirstOrDefault()
?? throw new InvalidOperationException($"Envelope creation failed. Parameters:" + ?? throw new InvalidOperationException($"Envelope creation failed. Parameters:" +
$"userId={userId}, title='{title}', message='{message}', tfaEnabled={tfaEnabled}."); ; $"userId={userId}, title='{title}', message='{message}', tfaEnabled={tfaEnabled}."); ;
return await _envelopeRepository.ReadByUuidAsync(envelope.Uuid, withAll: true) envelope.User = await _userRepository.ReadByIdAsync(envelope.UserId);
?? throw new InvalidOperationException($"Envelope creation succeeded but retrieval failed. Parameters:" +
$"userId={userId}, title='{title}', message='{message}', tfaEnabled={tfaEnabled}."); return envelope;
} }
} }