- ValidatePdfQueryHandler: Convert byte[] → MemoryStream before calling IPdfProcessor - ValidatePdfAQueryHandler: Same pattern - Update AutoMapper namespace imports (remove Domain.Models.ValueObjects references)
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using AutoMapper;
|
|
using DocumentOperator.Application.Common.DTOs;
|
|
using DocumentOperator.Application.Common.Interfaces;
|
|
using MediatR;
|
|
|
|
namespace DocumentOperator.Application.ValidatePdfA.Queries;
|
|
|
|
/// <summary>
|
|
/// Query for PDF/A validation (supports both byte array and Base64 input)
|
|
/// </summary>
|
|
public record ValidatePdfAQuery : IRequest<PdfAValidationResult>
|
|
{
|
|
/// <summary>
|
|
/// PDF as byte array (direct upload)
|
|
/// </summary>
|
|
public byte[]? PdfBytes { get; init; }
|
|
|
|
/// <summary>
|
|
/// PDF as Base64 string (API clients)
|
|
/// </summary>
|
|
public string? Base64Pdf { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handler for ValidatePdfAQuery
|
|
/// Orchestrates PDF/A validation using IPdfProcessor and AutoMapper
|
|
/// </summary>
|
|
public class ValidatePdfAQueryHandler(IPdfProcessor PdfProcessor, IMapper Mapper)
|
|
: IRequestHandler<ValidatePdfAQuery, PdfAValidationResult>
|
|
{
|
|
/// <summary>
|
|
/// Validates PDF/A and returns metadata with conformance level
|
|
/// </summary>
|
|
public async Task<PdfAValidationResult> Handle(ValidatePdfAQuery request, CancellationToken cancellationToken)
|
|
{
|
|
// Use byte[] if available, otherwise convert Base64
|
|
byte[] pdfBytes = request.PdfBytes ?? Convert.FromBase64String(request.Base64Pdf!);
|
|
|
|
// Convert to stream for IPdfProcessor
|
|
using var pdfStream = new MemoryStream(pdfBytes);
|
|
|
|
// Call DevExpress service (exceptions propagate naturally)
|
|
var metadata = await PdfProcessor.ValidatePdfAAsync(pdfStream);
|
|
|
|
// Map DTO to response DTO using AutoMapper
|
|
return Mapper.Map<PdfAValidationResult>(metadata);
|
|
}
|
|
}
|