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,24 @@
|
||||
using MediatR;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Envelopes.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// Befehl zur Erstellung eines Umschlags.
|
||||
/// </summary>
|
||||
/// <param name="Title">Der Titel des Umschlags. Dies ist ein Pflichtfeld.</param>
|
||||
/// <param name="Message">Die Nachricht, die im Umschlag enthalten sein soll. Dies ist ein Pflichtfeld.</param>
|
||||
/// <param name="TFAEnabled">Gibt an, ob die Zwei-Faktor-Authentifizierung für den Umschlag aktiviert ist. Standardmäßig false.</param>
|
||||
public record CreateEnvelopeCommand(
|
||||
[Required] string Title,
|
||||
[Required] string Message,
|
||||
bool TFAEnabled = false
|
||||
) : IRequest<CreateEnvelopeResponse?>
|
||||
{
|
||||
/// <summary>
|
||||
/// Id of receiver
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int? UserId { get; set; }
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace EnvelopeGenerator.Application.Envelopes.Commands;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CreateEnvelopeResponse
|
||||
{
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Envelopes.Commands;
|
||||
/// <summary>
|
||||
@@ -10,5 +11,19 @@ public class CreateEnvelopeSQL : ISQL<Envelope>
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Raw => string.Empty;
|
||||
public string Raw => @"
|
||||
USE [DD_ECM];
|
||||
DECLARE @OUT_UID varchar(36);
|
||||
|
||||
EXEC [dbo].[PRSIG_API_CREATE_ENVELOPE]
|
||||
@USER_ID = @UserId,
|
||||
@TITLE = @Title,
|
||||
@TFAEnabled = @TfaEnabled,
|
||||
@MESSAGE = @Message,
|
||||
@OUT_UID = @OUT_UID OUTPUT;
|
||||
|
||||
SELECT *
|
||||
FROM [dbo].[TBSIG_ENVELOPE]
|
||||
WHERE [ENVELOPE_UUID] = @OUT_UID;
|
||||
";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user