Refactor EnvelopeReceiverExecutor and Repository methods
- Updated `EnvelopeReceiverExecutor` to inherit from `SQLExecutor` and added `_erRepository` for enhanced data access. - Introduced `AddEnvelopeReceiverAsync` method for retrieving envelope receivers. - Modified `ReadById` in `EnvelopeReceiverRepository` to support flexible querying with new parameters. - Updated `ReadByIdAsync` to align with changes in `ReadById`.
This commit is contained in:
parent
749366fff5
commit
82fc7fa762
@ -1,6 +1,5 @@
|
||||
using Dapper;
|
||||
using DigitalData.UserManager.Application.Contracts.Repositories;
|
||||
using DigitalData.UserManager.Infrastructure.Repositories;
|
||||
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
||||
using EnvelopeGenerator.Application.SQL;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
@ -15,7 +14,7 @@ public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public EnvelopeExecutor(ILogger<EnvelopeExecutor> logger, IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IUserRepository userRepository) : base(provider, sqlExecutorParamsOptions)
|
||||
public EnvelopeExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IUserRepository userRepository) : base(provider, sqlExecutorParamsOptions)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
@ -1,7 +1,35 @@
|
||||
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
||||
using Dapper;
|
||||
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 EnvelopeReceiverExecutor: IEnvelopeReceiverExecutor
|
||||
public class EnvelopeReceiverExecutor: SQLExecutor, IEnvelopeReceiverExecutor
|
||||
{
|
||||
private readonly IEnvelopeReceiverRepository _erRepository;
|
||||
|
||||
public EnvelopeReceiverExecutor(ILogger<EnvelopeExecutor> logger, IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IEnvelopeReceiverRepository erRepository) : base(provider, sqlExecutorParamsOptions)
|
||||
{
|
||||
_erRepository = erRepository;
|
||||
}
|
||||
|
||||
public async Task<EnvelopeReceiver?> AddEnvelopeReceiverAsync(DynamicParameters parameters, bool addEnvelope = true, CancellationToken cancellation = default)
|
||||
{
|
||||
using var connection = new SqlConnection(Params.ConnectionString);
|
||||
var sql = Provider.GetRequiredService<EnvelopeReceiverAddReadSQL>();
|
||||
await connection.OpenAsync(cancellation);
|
||||
var envelopeReceivers = await connection.QueryAsync<EnvelopeReceiver>(sql.Raw, parameters);
|
||||
var er = envelopeReceivers.FirstOrDefault();
|
||||
|
||||
if (er is null)
|
||||
return null;
|
||||
|
||||
return await _erRepository.ReadByIdAsync(envelopeId: er.EnvelopeId, receiverId: er.ReceiverId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,9 +48,19 @@ public class EnvelopeReceiverRepository : CRUDRepository<EnvelopeReceiver, (int
|
||||
|
||||
public async Task<int> CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync();
|
||||
|
||||
private IQueryable<EnvelopeReceiver> ReadById(int envelopeId, int receiverId, bool readOnly = true)
|
||||
private IQueryable<EnvelopeReceiver> ReadById(int envelopeId, int receiverId, bool withEnvelope = true, bool withReceiver = true, bool readOnly = true)
|
||||
{
|
||||
var query = readOnly ? _dbSet.AsNoTracking() : _dbSet;
|
||||
|
||||
if (withEnvelope)
|
||||
query = query
|
||||
.Include(er => er.Envelope).ThenInclude(e => e!.Documents!).ThenInclude(d => d.Elements!.Where(e => e.Receiver!.Id == receiverId))
|
||||
.Include(er => er.Envelope).ThenInclude(e => e!.History)
|
||||
.Include(er => er.Envelope).ThenInclude(e => e!.User);
|
||||
|
||||
if (withReceiver)
|
||||
query = query.Include(er => er.Receiver);
|
||||
|
||||
return query.Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user