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.
29 lines
1.3 KiB
C#
29 lines
1.3 KiB
C#
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}'.");
|
|
}
|
|
}
|