refactor(CreateReceiverCommand): add handler
This commit is contained in:
parent
b939e19334
commit
cc2db8716e
@ -1,4 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
@ -9,7 +12,7 @@ namespace EnvelopeGenerator.Application.Receivers.Commands;
|
||||
///
|
||||
/// </summary>
|
||||
[ApiExplorerSettings(IgnoreApi = true)]
|
||||
public record CreateReceiverCommand
|
||||
public record CreateReceiverCommand : IRequest<int>
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
@ -44,3 +47,35 @@ public record CreateReceiverCommand
|
||||
/// </summary>
|
||||
public DateTime AddedWhen { get; } = DateTime.Now;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CreateReceiverCommandHandler : IRequestHandler<CreateReceiverCommand, int>
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private readonly IRepository<Receiver> _repo;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
public CreateReceiverCommandHandler(IRepository<Receiver> repo)
|
||||
{
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancel"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> Handle(CreateReceiverCommand request, CancellationToken cancel)
|
||||
{
|
||||
Receiver receiver = await _repo.CreateAsync(request, cancel);
|
||||
return receiver.Id;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user