refactor(application): migrate all queries to Stream-based API
- Replace byte[] and Base64String with required Stream PdfStream - Simplify validators: remove XOR/Base64 validation, only check NotNull - Affected queries: ValidatePdfQuery, ValidatePdfAQuery, CheckPdfAttachmentsQuery, ExtractSwissQrCodeQuery - Memory efficiency: direct stream usage, no intermediate byte[] copies
This commit is contained in:
@@ -6,19 +6,14 @@ using MediatR;
|
||||
namespace DocumentOperator.Application.CheckPdfAttachments.Queries;
|
||||
|
||||
/// <summary>
|
||||
/// Query for checking PDF attachments (supports both byte array and Base64 input)
|
||||
/// Query for checking PDF attachments (Stream-based)
|
||||
/// </summary>
|
||||
public record CheckPdfAttachmentsQuery : IRequest<AttachmentCheckResult>
|
||||
{
|
||||
/// <summary>
|
||||
/// PDF as byte array (direct upload via multipart/form-data)
|
||||
/// PDF as stream (caller is responsible for disposal)
|
||||
/// </summary>
|
||||
public byte[]? PdfBytes { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// PDF as Base64 string (for API clients using application/json)
|
||||
/// </summary>
|
||||
public string? Base64Pdf { get; init; }
|
||||
public required Stream PdfStream { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -33,14 +28,8 @@ public class CheckPdfAttachmentsQueryHandler(IPdfProcessor PdfProcessor, IMapper
|
||||
/// </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);
|
||||
// Call DevExpress service directly with stream (exceptions propagate naturally)
|
||||
var attachmentInfo = await PdfProcessor.CheckAttachmentsAsync(request.PdfStream);
|
||||
|
||||
// Map DTO to response DTO using AutoMapper
|
||||
return Mapper.Map<AttachmentCheckResult>(attachmentInfo);
|
||||
|
||||
Reference in New Issue
Block a user