42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using AutoMapper;
|
|
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.Envelopes.Commands;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class CreateEnvelopeCommandHandler : IRequestHandler<CreateEnvelopeCommand, CreateEnvelopeResponse?>
|
|
{
|
|
private readonly IEnvelopeExecutor _envelopeExecutor;
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="envelopeExecutor"></param>
|
|
/// <param name="mapper"></param>
|
|
public CreateEnvelopeCommandHandler(IEnvelopeExecutor envelopeExecutor, IMapper mapper)
|
|
{
|
|
_envelopeExecutor = envelopeExecutor;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public async Task<CreateEnvelopeResponse?> Handle(CreateEnvelopeCommand request, CancellationToken cancellationToken)
|
|
{
|
|
int userId = request.UserId ?? throw new InvalidOperationException("UserId cannot be null when creating an envelope.");
|
|
|
|
var envelope = await _envelopeExecutor.CreateEnvelopeAsync(userId, request.Title, request.Message, request.TFAEnabled, cancellationToken);
|
|
|
|
return _mapper.Map<CreateEnvelopeResponse>(envelope);
|
|
}
|
|
}
|