Updated project and solution files to rename and restructure `DocumentOperator` to `DocumentService`. Modified project references in `DocumentService.API.csproj`, `DocumentService.Application.csproj`, and `DocumentService.Infrastructure.csproj` to reflect the new naming convention. Updated `DocumentService.sln` to remove old project references, add new ones, and adjust configuration and nested project mappings accordingly. This change aligns the project structure with the new naming convention.
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using DocumentService.Application.Common.Interfaces;
|
|
using FluentValidation;
|
|
using MediatR;
|
|
|
|
namespace DocumentService.Application.ConvertToPdfA;
|
|
|
|
/// <summary>
|
|
/// Command to convert a standard PDF to PDF/A format
|
|
/// </summary>
|
|
public record ConvertToPdfACommand : IRequest<byte[]>
|
|
{
|
|
/// <summary>
|
|
/// PDF document stream. Must be positioned at the beginning (Position = 0).
|
|
/// </summary>
|
|
public required Stream PdfStream { get; init; }
|
|
|
|
/// <summary>
|
|
/// Target PDF/A level (e.g., "PDF/A-1b", "PDF/A-2b", "PDF/A-3b")
|
|
/// </summary>
|
|
public required string PdfALevel { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handler for ConvertToPdfACommand
|
|
/// </summary>
|
|
public class ConvertToPdfACommandHandler(IPdfProcessor pdfProcessor)
|
|
: IRequestHandler<ConvertToPdfACommand, byte[]>
|
|
{
|
|
public async Task<byte[]> Handle(ConvertToPdfACommand request, CancellationToken cancellationToken)
|
|
{
|
|
return await pdfProcessor.ConvertToPdfAAsync(request.PdfStream, request.PdfALevel);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validator for ConvertToPdfACommand
|
|
/// </summary>
|
|
public class ConvertToPdfACommandValidator : AbstractValidator<ConvertToPdfACommand>
|
|
{
|
|
private static readonly string[] ValidPdfALevels =
|
|
{
|
|
"PDF/A-1b", "PDF/A-1a",
|
|
"PDF/A-2b", "PDF/A-2u", "PDF/A-2a",
|
|
"PDF/A-3b", "PDF/A-3u", "PDF/A-3a"
|
|
};
|
|
|
|
public ConvertToPdfACommandValidator()
|
|
{
|
|
RuleFor(x => x.PdfStream)
|
|
.NotNull()
|
|
.WithMessage("PDF stream is required");
|
|
|
|
RuleFor(x => x.PdfALevel)
|
|
.NotEmpty()
|
|
.WithMessage("PDF/A level is required")
|
|
.Must(level => ValidPdfALevels.Contains(level, StringComparer.OrdinalIgnoreCase))
|
|
.WithMessage($"Invalid PDF/A level. Valid values: {string.Join(", ", ValidPdfALevels)}");
|
|
}
|
|
}
|