feat(CreateAnnotationCommand): implement CreateAnnotationCommand and handler logic

Added full implementation for CreateAnnotationCommand and its handler:
- Introduced `PSPDFKitInstantJSON` property to the command
- Injected repositories for `Signature` and `Annotation`
- Implemented query filtering for Envelope and Receiver
- Added annotation creation from parsed PSPDFKit JSON
- Created helper method `ParsePSPDFKitInstantJSON` for JSON parsing
This commit is contained in:
2025-10-13 15:28:38 +02:00
parent faa37e0dcd
commit f56928f44f
9 changed files with 95 additions and 16 deletions

View File

@@ -1,18 +1,50 @@
using EnvelopeGenerator.Application.Common.Query;
using DigitalData.Core.Abstraction.Application.Repository;
using EnvelopeGenerator.Application.Common.Extensions;
using EnvelopeGenerator.Application.Common.Query;
using EnvelopeGenerator.Domain.Entities;
using MediatR;
using Microsoft.EntityFrameworkCore;
using System.Text.Json.Serialization;
namespace EnvelopeGenerator.Application.Annotations.Commands;
/// <summary>
///
/// </summary>
public record CreateAnnotationCommand : EnvelopeReceiverQueryBase, IRequest;
public record CreateAnnotationCommand : EnvelopeReceiverQueryBase, IRequest
{
/// <summary>
///
/// </summary>
[JsonIgnore]
public string PSPDFKitInstantJSON { get; set; } = null!;
}
/// <summary>
///
/// </summary>
public class CreateAnnotationCommandHandler : IRequestHandler<CreateAnnotationCommand>
{
/// <summary>
///
/// </summary>
private readonly IRepository<Signature> _signRepo;
/// <summary>
///
/// </summary>
private readonly IRepository<Annotation> _annotRepo;
/// <summary>
///
/// </summary>
/// <param name="signRepo"></param>
public CreateAnnotationCommandHandler(IRepository<Signature> signRepo, IRepository<Annotation> annotRepo)
{
_signRepo = signRepo;
_annotRepo = annotRepo;
}
/// <summary>
///
/// </summary>
@@ -20,8 +52,50 @@ public class CreateAnnotationCommandHandler : IRequestHandler<CreateAnnotationCo
/// <param name="cancel"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public Task Handle(CreateAnnotationCommand request, CancellationToken cancel)
public async Task Handle(CreateAnnotationCommand request, CancellationToken cancel)
{
throw new NotImplementedException();
var query = _signRepo.Query;
#region Envelope Query
if (request.Envelope.Id is int envelopeId)
query = query.Where(annot => annot.Document.EnvelopeId == envelopeId);
if (request.Envelope.Uuid is string envelopeUuid)
query = query.Where(annot => annot.Document.Envelope!.Uuid == envelopeUuid);
#endregion
// Receiver Query
query = query.Where(request.Receiver);
var elements = await query.ToListAsync(cancel);
foreach (var element in elements)
{
var annots = ParsePSPDFKitInstantJSON(request.PSPDFKitInstantJSON, element.Id)
.Select(annot => new Annotation()
{
ElementId = element.Id,
Name = annot.Key,
Value = annot.Value,
AddedWhen = DateTime.UtcNow
});
await _annotRepo.CreateAsync(annots, cancel);
}
}
/// <summary>
///
/// </summary>
/// <param name="json"></param>
/// <param name="elementId"></param>
/// <returns></returns>
public static Dictionary<string, string> ParsePSPDFKitInstantJSON(string json, int elementId)
{
Dictionary<string, string> annots = new();
// parse json here
return annots;
}
}

View File

@@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.66" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.3.5" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.3.6" />
<PackageReference Include="DigitalData.Core.Application" Version="3.4.0" />
<PackageReference Include="DigitalData.Core.Client" Version="2.1.0" />
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />