refactor: Update Application handlers to convert byte[] to Stream
- ValidatePdfQueryHandler: Convert byte[] → MemoryStream before calling IPdfProcessor - ValidatePdfAQueryHandler: Same pattern - Update AutoMapper namespace imports (remove Domain.Models.ValueObjects references)
This commit is contained in:
@@ -43,5 +43,12 @@ public class MappingProfile : Profile
|
|||||||
CreateMap<AlternativeScheme, AlternativeSchemeDto>()
|
CreateMap<AlternativeScheme, AlternativeSchemeDto>()
|
||||||
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name ?? string.Empty))
|
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name ?? string.Empty))
|
||||||
.ForMember(dest => dest.Instruction, opt => opt.MapFrom(src => src.Instruction ?? string.Empty));
|
.ForMember(dest => dest.Instruction, opt => opt.MapFrom(src => src.Instruction ?? string.Empty));
|
||||||
|
|
||||||
|
// AttachmentInfo -> AttachmentCheckResult
|
||||||
|
CreateMap<AttachmentInfo, AttachmentCheckResult>();
|
||||||
|
|
||||||
|
// AttachmentMetadata -> AttachmentDto
|
||||||
|
CreateMap<AttachmentMetadata, AttachmentDto>()
|
||||||
|
.ForMember(dest => dest.Size, opt => opt.MapFrom(src => src.SizeBytes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,13 @@ public class ValidatePdfQueryHandler(IPdfProcessor PdfProcessor, IMapper Mapper)
|
|||||||
// Use byte[] if available, otherwise convert Base64
|
// Use byte[] if available, otherwise convert Base64
|
||||||
byte[] pdfBytes = request.PdfBytes ?? Convert.FromBase64String(request.Base64Pdf!);
|
byte[] pdfBytes = request.PdfBytes ?? Convert.FromBase64String(request.Base64Pdf!);
|
||||||
|
|
||||||
// Call DevExpress service (can throw PdfProcessingException)
|
// Convert to stream for IPdfProcessor (using MemoryStream)
|
||||||
var metadata = await PdfProcessor.ValidateAsync(pdfBytes);
|
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<PdfValidationResult>(metadata);
|
return Mapper.Map<PdfValidationResult>(metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,13 @@ public class ValidatePdfAQueryHandler(IPdfProcessor PdfProcessor, IMapper Mapper
|
|||||||
// Use byte[] if available, otherwise convert Base64
|
// Use byte[] if available, otherwise convert Base64
|
||||||
byte[] pdfBytes = request.PdfBytes ?? Convert.FromBase64String(request.Base64Pdf!);
|
byte[] pdfBytes = request.PdfBytes ?? Convert.FromBase64String(request.Base64Pdf!);
|
||||||
|
|
||||||
// Call DevExpress service (can throw PdfProcessingException)
|
// Convert to stream for IPdfProcessor
|
||||||
var metadata = await PdfProcessor.ValidatePdfAAsync(pdfBytes);
|
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<PdfAValidationResult>(metadata);
|
return Mapper.Map<PdfAValidationResult>(metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user