From f34770931f60fe9b389ed8f88fdffd5bdf1b3cdc Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 25 Aug 2025 17:33:49 +0200 Subject: [PATCH] feat(CreateHistoryCommand): add CreateHistoryCommandHandler with repository integration - Extend CreateHistoryCommand to implement IRequest - Introduce CreateHistoryCommandHandler to handle command via IRepository - Implement async creation and verification of EnvelopeHistory records --- .../Commands/CreateHistoryCommand.cs | 46 ++++++++++++++++++- .../Histories/MappingProfile.cs | 2 + 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/EnvelopeGenerator.Application/Histories/Commands/CreateHistoryCommand.cs b/EnvelopeGenerator.Application/Histories/Commands/CreateHistoryCommand.cs index ad228144..dd19e05e 100644 --- a/EnvelopeGenerator.Application/Histories/Commands/CreateHistoryCommand.cs +++ b/EnvelopeGenerator.Application/Histories/Commands/CreateHistoryCommand.cs @@ -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; /// /// /// -public record CreateHistoryCommand +public record CreateHistoryCommand : IRequest { /// /// @@ -36,4 +40,42 @@ public record CreateHistoryCommand /// /// public string? Comment { get; set; } +} + +/// +/// +/// +public class CreateHistoryCommandHandler : IRequestHandler +{ + private readonly IRepository _repo; + + /// + /// + /// + /// + public CreateHistoryCommandHandler(IRepository repo) + { + _repo = repo; + } + + /// + /// + /// + /// + /// + /// + public async Task 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; + } } \ No newline at end of file diff --git a/EnvelopeGenerator.Application/Histories/MappingProfile.cs b/EnvelopeGenerator.Application/Histories/MappingProfile.cs index b1f7ca6a..8ce5c5bc 100644 --- a/EnvelopeGenerator.Application/Histories/MappingProfile.cs +++ b/EnvelopeGenerator.Application/Histories/MappingProfile.cs @@ -1,4 +1,5 @@ using AutoMapper; +using EnvelopeGenerator.Application.Histories.Commands; using EnvelopeGenerator.Application.Histories.Queries.Read; using EnvelopeGenerator.Domain.Entities; @@ -15,5 +16,6 @@ public class MappingProfile: Profile public MappingProfile() { CreateMap(); + CreateMap(); } }