Add envelope creation functionality and SQL integration
- Updated `EnvelopeGenerator.Application.csproj` to include `Microsoft.Data.SqlClient` package. - Refactored `CreateEnvelopeReceiverCommand` to inherit from `CreateEnvelopeCommand`. - Enhanced `CreateEnvelopeSQL` with a SQL script for envelope creation. - Introduced `CreateEnvelopeCommand` to encapsulate envelope creation data. - Added `CreateEnvelopeCommandHandler` to process commands and interact with the database. - Created `CreateEnvelopeResponse` class for handling responses from envelope creation.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using AutoMapper;
|
||||
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Envelopes.Commands;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CreateEnvelopeCommandHandler : IRequestHandler<CreateEnvelopeCommand, CreateEnvelopeResponse?>
|
||||
{
|
||||
private readonly ISQLExecutor<Envelope> _sqlExecutor;
|
||||
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sqlExecutor"></param>
|
||||
/// <param name="mapper"></param>
|
||||
public CreateEnvelopeCommandHandler(ISQLExecutor<Envelope> sqlExecutor, IMapper mapper)
|
||||
{
|
||||
_sqlExecutor = sqlExecutor;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<CreateEnvelopeResponse?> Handle(CreateEnvelopeCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
object[] parameters = new object[]
|
||||
{
|
||||
new SqlParameter("@UserId", request.UserId),
|
||||
new SqlParameter("@Title", request.Title),
|
||||
new SqlParameter("@TfaEnabled", request.TFAEnabled ? 1 : 0),
|
||||
new SqlParameter("@Message", request.Message)
|
||||
};
|
||||
|
||||
var envelope = await _sqlExecutor.Execute<CreateEnvelopeSQL>(cancellationToken, parameters).FirstOrDefaultAsync();
|
||||
|
||||
return _mapper.Map<CreateEnvelopeResponse>(envelope);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user