- Add CheckPdfAttachmentsQuery with dual input support (byte[] + Base64) - Add CheckPdfAttachmentsQueryHandler with IPdfProcessor integration - Add CheckPdfAttachmentsQueryValidator with FluentValidation rules - Add AttachmentCheckResult DTO for API response - Handler converts byte[] → MemoryStream for IPdfProcessor.CheckAttachmentsAsync() - AutoMapper maps AttachmentInfo → AttachmentCheckResult
49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using AutoMapper;
|
|
using DocumentOperator.Application.Common.DTOs;
|
|
using DocumentOperator.Application.Common.Interfaces;
|
|
using MediatR;
|
|
|
|
namespace DocumentOperator.Application.CheckPdfAttachments.Queries;
|
|
|
|
/// <summary>
|
|
/// Query for checking PDF attachments (supports both byte array and Base64 input)
|
|
/// </summary>
|
|
public record CheckPdfAttachmentsQuery : IRequest<AttachmentCheckResult>
|
|
{
|
|
/// <summary>
|
|
/// PDF as byte array (direct upload via multipart/form-data)
|
|
/// </summary>
|
|
public byte[]? PdfBytes { get; init; }
|
|
|
|
/// <summary>
|
|
/// PDF as Base64 string (for API clients using application/json)
|
|
/// </summary>
|
|
public string? Base64Pdf { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handler for CheckPdfAttachmentsQuery
|
|
/// Orchestrates PDF attachment checking using IPdfProcessor and AutoMapper
|
|
/// </summary>
|
|
public class CheckPdfAttachmentsQueryHandler(IPdfProcessor PdfProcessor, IMapper Mapper)
|
|
: IRequestHandler<CheckPdfAttachmentsQuery, AttachmentCheckResult>
|
|
{
|
|
/// <summary>
|
|
/// Checks PDF attachments and returns detailed metadata
|
|
/// </summary>
|
|
public async Task<AttachmentCheckResult> Handle(CheckPdfAttachmentsQuery 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 attachmentInfo = await PdfProcessor.CheckAttachmentsAsync(pdfStream);
|
|
|
|
// Map DTO to response DTO using AutoMapper
|
|
return Mapper.Map<AttachmentCheckResult>(attachmentInfo);
|
|
}
|
|
}
|