Add IDocumentExecutor interface and DocumentExecutor class
Introduces the `IDocumentExecutor` interface with a method `CreateDocumentAsync` for asynchronous document creation. Implements the `DocumentExecutor` class that inherits from `SQLExecutor`, providing the functionality to create documents using a SQL connection and handle potential errors during the process.
This commit is contained in:
parent
95a1fd1355
commit
bce29aa31a
@ -0,0 +1,18 @@
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface IDocumentExecutor
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="base64"></param>
|
||||
/// <param name="envelope_uuid"></param>
|
||||
/// <param name="cancellation"></param>
|
||||
/// <returns></returns>
|
||||
Task<EnvelopeDocument> CreateDocumentAsync(string base64, string envelope_uuid, CancellationToken cancellation = default);
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
using Dapper;
|
||||
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
||||
using EnvelopeGenerator.Application.SQL;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure.Executor;
|
||||
|
||||
public class DocumentExecutor : SQLExecutor, IDocumentExecutor
|
||||
{
|
||||
public DocumentExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions) : base(provider, sqlExecutorParamsOptions)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<EnvelopeDocument> CreateDocumentAsync(string base64, string envelope_uuid, CancellationToken cancellation = default)
|
||||
{
|
||||
using var connection = new SqlConnection(Params.ConnectionString);
|
||||
var sql = Provider.GetRequiredService<DocumentCreateReadSQL>();
|
||||
await connection.OpenAsync(cancellation);
|
||||
var parameters = DocumentCreateReadSQL.CreateParmas(base64, envelope_uuid);
|
||||
var documents = await connection.QueryAsync<EnvelopeDocument>(sql.Raw, parameters);
|
||||
return documents.FirstOrDefault()
|
||||
?? throw new InvalidOperationException($"Document creation failed. Parameters:" +
|
||||
$"base64={base64}, envelope_uuid='{envelope_uuid}'.");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user