diff --git a/EnvelopeGenerator.Infrastructure/Executor/EnvelopeExecutor.cs b/EnvelopeGenerator.Infrastructure/Executor/EnvelopeExecutor.cs index b44bb28a..0933997c 100644 --- a/EnvelopeGenerator.Infrastructure/Executor/EnvelopeExecutor.cs +++ b/EnvelopeGenerator.Infrastructure/Executor/EnvelopeExecutor.cs @@ -6,18 +6,17 @@ 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; + private readonly IUserRepository _userRepository; - public EnvelopeExecutor(IServiceProvider provider, IOptions sqlExecutorParamsOptions, IEnvelopeRepository envelopeRepository) : base(provider, sqlExecutorParamsOptions) + public EnvelopeExecutor(IServiceProvider provider, IOptions sqlExecutorParamsOptions, IUserRepository userRepository) : base(provider, sqlExecutorParamsOptions) { - _envelopeRepository = envelopeRepository; + _userRepository = userRepository; } public async Task 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() ?? throw new InvalidOperationException($"Envelope creation failed. Parameters:" + $"userId={userId}, title='{title}', message='{message}', tfaEnabled={tfaEnabled}."); ; - - return await _envelopeRepository.ReadByUuidAsync(envelope.Uuid, withAll: true) - ?? throw new InvalidOperationException($"Envelope creation succeeded but retrieval failed. Parameters:" + - $"userId={userId}, title='{title}', message='{message}', tfaEnabled={tfaEnabled}."); + + envelope.User = await _userRepository.ReadByIdAsync(envelope.UserId); + + return envelope; } } \ No newline at end of file