This commit implements a complete rebranding of the project: - Updated all namespaces from `DocumentOperator` to `DocumentService`. - Renamed file paths, embedded resources, and test data references. - Updated configuration keys, logging paths, and Redis instance names. - Revised documentation to reflect the new project name. - Modified project and solution files to align with the new structure. - Updated class names, DTOs, commands, queries, and handlers. - Adjusted middleware, controllers, and API endpoints. - Updated Swagger metadata and API titles to `DocumentService API`. - Refactored test namespaces, resource paths, and embedded resources. - Updated build and deployment configurations for the new name. - Replaced all references to `DocumentOperator` in comments and literals. These changes ensure consistency across the codebase and documentation.
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)}");
|
|
}
|
|
}
|