refactor(annotation): add lazy JSON deserialization for PSPDFKitInstantJSON
- Introduced Lazy<dynamic> field for deferred deserialization of PSPDFKitInstantJSON - Added ExpandoObject property (PSPDFKitInstant) for dynamic access - Updated handler to use ParsePSPDFKitInstant instead of ParsePSPDFKitInstantJSON - Improved JsonSerializerOptions for case-insensitive property handling
This commit is contained in:
parent
5e53f2b691
commit
d10f19d92a
@ -5,6 +5,8 @@ using EnvelopeGenerator.Application.Common.Query;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Dynamic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Annotations.Commands;
|
||||
@ -14,11 +16,36 @@ namespace EnvelopeGenerator.Application.Annotations.Commands;
|
||||
/// </summary>
|
||||
public record CreateAnnotationCommand : EnvelopeReceiverQueryBase, IRequest<IEnumerable<Signature>>
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public CreateAnnotationCommand()
|
||||
{
|
||||
_lazyPSPDFKitInstant = new(() =>
|
||||
{
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = null
|
||||
};
|
||||
|
||||
return JsonSerializer.Deserialize<dynamic>(PSPDFKitInstantJSON, options) ?? new ExpandoObject();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string PSPDFKitInstantJSON { get; set; } = null!;
|
||||
|
||||
private readonly Lazy<dynamic> _lazyPSPDFKitInstant;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public ExpandoObject PSPDFKitInstant => _lazyPSPDFKitInstant.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -72,7 +99,7 @@ public class CreateAnnotationCommandHandler : IRequestHandler<CreateAnnotationCo
|
||||
|
||||
foreach (var element in elements)
|
||||
{
|
||||
var annots = ParsePSPDFKitInstantJSON(request.PSPDFKitInstantJSON, element.Id)
|
||||
var annots = ParsePSPDFKitInstant(request.PSPDFKitInstant, element.Id)
|
||||
.Select(annot => new Annotation()
|
||||
{
|
||||
ElementId = element.Id,
|
||||
@ -90,10 +117,10 @@ public class CreateAnnotationCommandHandler : IRequestHandler<CreateAnnotationCo
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="json"></param>
|
||||
/// <param name="instant"></param>
|
||||
/// <param name="elementId"></param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, string> ParsePSPDFKitInstantJSON(string json, int elementId)
|
||||
public static Dictionary<string, string> ParsePSPDFKitInstant(ExpandoObject instant, int elementId)
|
||||
{
|
||||
Dictionary<string, string> annots = new();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user