feat(CreateHistoryCommand): add CreateHistoryCommandHandler with repository integration
- Extend CreateHistoryCommand to implement IRequest<long?> - Introduce CreateHistoryCommandHandler to handle command via IRepository<EnvelopeHistory> - Implement async creation and verification of EnvelopeHistory records
This commit is contained in:
parent
78100ef24f
commit
f34770931f
@ -1,11 +1,15 @@
|
|||||||
using EnvelopeGenerator.Domain;
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using EnvelopeGenerator.Domain;
|
||||||
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Histories.Commands;
|
namespace EnvelopeGenerator.Application.Histories.Commands;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record CreateHistoryCommand
|
public record CreateHistoryCommand : IRequest<long?>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -36,4 +40,42 @@ public record CreateHistoryCommand
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Comment { get; set; }
|
public string? Comment { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class CreateHistoryCommandHandler : IRequestHandler<CreateHistoryCommand, long?>
|
||||||
|
{
|
||||||
|
private readonly IRepository<EnvelopeHistory> _repo;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="repo"></param>
|
||||||
|
public CreateHistoryCommandHandler(IRepository<EnvelopeHistory> repo)
|
||||||
|
{
|
||||||
|
_repo = repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancel"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<long?> Handle(CreateHistoryCommand request, CancellationToken cancel)
|
||||||
|
{
|
||||||
|
// create entitiy
|
||||||
|
await _repo.CreateAsync(request, cancel);
|
||||||
|
|
||||||
|
// check if created
|
||||||
|
var record = await _repo.ReadOnly()
|
||||||
|
.Where(h => h.EnvelopeId == request.EnvelopeId)
|
||||||
|
.Where(h => h.UserReference == request.UserReference)
|
||||||
|
.Where(h => h.ActionDate == request.ActionDate)
|
||||||
|
.SingleOrDefaultAsync(cancel);
|
||||||
|
|
||||||
|
return record?.Id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using EnvelopeGenerator.Application.Histories.Commands;
|
||||||
using EnvelopeGenerator.Application.Histories.Queries.Read;
|
using EnvelopeGenerator.Application.Histories.Queries.Read;
|
||||||
using EnvelopeGenerator.Domain.Entities;
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
|
|
||||||
@ -15,5 +16,6 @@ public class MappingProfile: Profile
|
|||||||
public MappingProfile()
|
public MappingProfile()
|
||||||
{
|
{
|
||||||
CreateMap<EnvelopeHistory, ReadHistoryResponse>();
|
CreateMap<EnvelopeHistory, ReadHistoryResponse>();
|
||||||
|
CreateMap<CreateHistoryCommand, EnvelopeHistory>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user