feat: Add ExtractPdfAttachments Application layer (Command/Handler/Validator merged)

This commit is contained in:
2026-07-21 09:26:04 +02:00
parent 0f4d860176
commit 1989ca7ef7

View File

@@ -0,0 +1,43 @@
using DocumentOperator.Application.Common.Interfaces;
using FluentValidation;
using MediatR;
namespace DocumentOperator.Application.ExtractPdfAttachments;
/// <summary>
/// Command to extract all embedded files from a PDF document and return as ZIP archive.
/// </summary>
public record ExtractPdfAttachmentsCommand : IRequest<byte[]>
{
/// <summary>
/// PDF document stream. Must be positioned at the beginning (Position = 0).
/// </summary>
public required Stream PdfStream { get; init; }
}
/// <summary>
/// Handler for ExtractPdfAttachmentsCommand.
/// Extracts all embedded files from PDF and returns as ZIP archive.
/// </summary>
public class ExtractPdfAttachmentsCommandHandler(IPdfProcessor pdfProcessor)
: IRequestHandler<ExtractPdfAttachmentsCommand, byte[]>
{
public async Task<byte[]> Handle(ExtractPdfAttachmentsCommand request, CancellationToken cancellationToken)
{
// Delegate to infrastructure layer
return await pdfProcessor.ExtractAttachmentsAsync(request.PdfStream);
}
}
/// <summary>
/// Validator for ExtractPdfAttachmentsCommand.
/// </summary>
public class ExtractPdfAttachmentsCommandValidator : AbstractValidator<ExtractPdfAttachmentsCommand>
{
public ExtractPdfAttachmentsCommandValidator()
{
RuleFor(x => x.PdfStream)
.NotNull()
.WithMessage("PDF stream is required");
}
}