From e13e85182a77ebf030a252ebdbc1a2ae6af4d0bf Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 20 Jul 2026 11:55:25 +0200 Subject: [PATCH] refactor: Update Application handlers to convert byte[] to Stream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ValidatePdfQueryHandler: Convert byte[] → MemoryStream before calling IPdfProcessor - ValidatePdfAQueryHandler: Same pattern - Update AutoMapper namespace imports (remove Domain.Models.ValueObjects references) --- .../Common/Mapping/MappingProfile.cs | 7 +++++++ .../ValidatePdf/Queries/ValidatePdfQuery.cs | 9 ++++++--- .../ValidatePdfA/Queries/ValidatePdfAQuery.cs | 9 ++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/DocumentOperator.Application/Common/Mapping/MappingProfile.cs b/DocumentOperator.Application/Common/Mapping/MappingProfile.cs index 6018142..7203e27 100644 --- a/DocumentOperator.Application/Common/Mapping/MappingProfile.cs +++ b/DocumentOperator.Application/Common/Mapping/MappingProfile.cs @@ -43,5 +43,12 @@ public class MappingProfile : Profile CreateMap() .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name ?? string.Empty)) .ForMember(dest => dest.Instruction, opt => opt.MapFrom(src => src.Instruction ?? string.Empty)); + + // AttachmentInfo -> AttachmentCheckResult + CreateMap(); + + // AttachmentMetadata -> AttachmentDto + CreateMap() + .ForMember(dest => dest.Size, opt => opt.MapFrom(src => src.SizeBytes)); } } diff --git a/DocumentOperator.Application/ValidatePdf/Queries/ValidatePdfQuery.cs b/DocumentOperator.Application/ValidatePdf/Queries/ValidatePdfQuery.cs index 349bb93..0f08a5c 100644 --- a/DocumentOperator.Application/ValidatePdf/Queries/ValidatePdfQuery.cs +++ b/DocumentOperator.Application/ValidatePdf/Queries/ValidatePdfQuery.cs @@ -36,10 +36,13 @@ public class ValidatePdfQueryHandler(IPdfProcessor PdfProcessor, IMapper Mapper) // Use byte[] if available, otherwise convert Base64 byte[] pdfBytes = request.PdfBytes ?? Convert.FromBase64String(request.Base64Pdf!); - // Call DevExpress service (can throw PdfProcessingException) - var metadata = await PdfProcessor.ValidateAsync(pdfBytes); + // Convert to stream for IPdfProcessor (using MemoryStream) + using var pdfStream = new MemoryStream(pdfBytes); - // Map domain entity to DTO using AutoMapper + // Call DevExpress service (exceptions propagate naturally) + var metadata = await PdfProcessor.ValidateAsync(pdfStream); + + // Map DTO to response DTO using AutoMapper return Mapper.Map(metadata); } } diff --git a/DocumentOperator.Application/ValidatePdfA/Queries/ValidatePdfAQuery.cs b/DocumentOperator.Application/ValidatePdfA/Queries/ValidatePdfAQuery.cs index c23445d..64cdcca 100644 --- a/DocumentOperator.Application/ValidatePdfA/Queries/ValidatePdfAQuery.cs +++ b/DocumentOperator.Application/ValidatePdfA/Queries/ValidatePdfAQuery.cs @@ -36,10 +36,13 @@ public class ValidatePdfAQueryHandler(IPdfProcessor PdfProcessor, IMapper Mapper // Use byte[] if available, otherwise convert Base64 byte[] pdfBytes = request.PdfBytes ?? Convert.FromBase64String(request.Base64Pdf!); - // Call DevExpress service (can throw PdfProcessingException) - var metadata = await PdfProcessor.ValidatePdfAAsync(pdfBytes); + // Convert to stream for IPdfProcessor + using var pdfStream = new MemoryStream(pdfBytes); - // Map domain entity to DTO using AutoMapper + // Call DevExpress service (exceptions propagate naturally) + var metadata = await PdfProcessor.ValidatePdfAAsync(pdfStream); + + // Map DTO to response DTO using AutoMapper return Mapper.Map(metadata); } }