From 55c20e83d8bbca9ca49b6153ffa18698d21ffd3c Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 7 Nov 2025 13:44:53 +0100 Subject: [PATCH] refactor: convert BurnPdfCommand to record and update handler to return byte[] - Changed `BurnPdfCommand` from empty class to a `record` with properties: `SourceBuffer`, `InstantJSONList`, `EnvelopeId`. - Updated `BurnPdfCommandHandler` to implement `IRequestHandler`. - Modified `Handle` method to be async and use the `request` data to return PDF bytes. - Removed obsolete `BurnPdfCommand` class and updated related logic accordingly. --- .../Pdf/BurnPdfCommand.cs | 43 +++++++------------ .../Entities/Signature.cs | 3 +- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/EnvelopeGenerator.Application/Pdf/BurnPdfCommand.cs b/EnvelopeGenerator.Application/Pdf/BurnPdfCommand.cs index 070c2d92..147a1abc 100644 --- a/EnvelopeGenerator.Application/Pdf/BurnPdfCommand.cs +++ b/EnvelopeGenerator.Application/Pdf/BurnPdfCommand.cs @@ -17,14 +17,12 @@ namespace EnvelopeGenerator.Application.Pdf; /// /// /// -public class BurnPdfCommand : IRequest -{ -} +public record BurnPdfCommand(byte[] SourceBuffer, List InstantJSONList, int EnvelopeId) : IRequest; /// /// /// -public class BurnPdfCommandHandler : IRequestHandler +public class BurnPdfCommandHandler : IRequestHandler { /// /// @@ -52,26 +50,6 @@ public class BurnPdfCommandHandler : IRequestHandler _logger = logger; } - /// - /// - /// - /// - /// - /// - /// - public byte[] BurnAnnotsToPDF(byte[] pSourceBuffer, List pInstantJSONList, int envelopeId) - { - // read the elements of envelope with their annotations - var elements = _signRepo - .Where(sig => sig.Document.EnvelopeId == envelopeId) - .Include(sig => sig.Annotations) - .ToList(); - - return elements.Any() - ? BurnElementAnnotsToPDF(pSourceBuffer, elements) - : BurnInstantJSONAnnotsToPDF(pSourceBuffer, pInstantJSONList); - } - /// /// /// @@ -347,7 +325,8 @@ public class BurnPdfCommandHandler : IRequestHandler _manager.AddFreeHandAnnot(oColor, oPoints); } } - private void AddInkAnnotation(Annotation pAnnotation) + + private void AddInkAnnotation(Annotation pAnnotation) { var oSegments = pAnnotation.Lines?.Points; var oColor = ColorTranslator.FromHtml(pAnnotation.StrokeColor ?? "#000000"); @@ -388,11 +367,19 @@ public class BurnPdfCommandHandler : IRequestHandler /// /// /// - /// + /// /// /// - public Task Handle(BurnPdfCommand request, CancellationToken cancellationToken) + public async Task Handle(BurnPdfCommand request, CancellationToken cancel) { - throw new NotImplementedException(); + // read the elements of envelope with their annotations + var elements = await _signRepo + .Where(sig => sig.Document.EnvelopeId == request.EnvelopeId) + .Include(sig => sig.Annotations) + .ToListAsync(cancel); + + return elements.Count > 0 + ? BurnElementAnnotsToPDF(request.SourceBuffer, elements) + : BurnInstantJSONAnnotsToPDF(request.SourceBuffer, request.InstantJSONList); } } \ No newline at end of file diff --git a/EnvelopeGenerator.Domain/Entities/Signature.cs b/EnvelopeGenerator.Domain/Entities/Signature.cs index 42f26a95..c267db0f 100644 --- a/EnvelopeGenerator.Domain/Entities/Signature.cs +++ b/EnvelopeGenerator.Domain/Entities/Signature.cs @@ -2,10 +2,11 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Text.Json.Serialization; #if NETFRAMEWORK using System; using System.Collections.Generic; +#elif NET +using System.Text.Json.Serialization; #endif namespace EnvelopeGenerator.Domain.Entities