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.
54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using DocumentService.Application.Common.Interfaces;
|
|
using FluentValidation;
|
|
using MediatR;
|
|
|
|
namespace DocumentService.Application.MergePdfs;
|
|
|
|
/// <summary>
|
|
/// Command to merge multiple PDF documents into a single PDF.
|
|
/// </summary>
|
|
public record MergePdfsCommand : IRequest<byte[]>
|
|
{
|
|
/// <summary>
|
|
/// PDF streams to merge. Minimum 2 required. Each must be at Position=0.
|
|
/// </summary>
|
|
public required IReadOnlyList<Stream> PdfStreams { get; init; }
|
|
|
|
/// <summary>
|
|
/// Optional page ranges per PDF (null = all pages).
|
|
/// Format: "1-3,5" means pages 1, 2, 3, and 5.
|
|
/// If provided, array length must match PdfStreams length.
|
|
/// </summary>
|
|
public IReadOnlyList<string?>? PageRanges { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handler for MergePdfsCommand.
|
|
/// Delegates PDF merge operation to infrastructure layer.
|
|
/// </summary>
|
|
public class MergePdfsCommandHandler(IPdfProcessor pdfProcessor)
|
|
: IRequestHandler<MergePdfsCommand, byte[]>
|
|
{
|
|
public async Task<byte[]> Handle(MergePdfsCommand request, CancellationToken cancellationToken)
|
|
{
|
|
return await pdfProcessor.MergePdfsAsync(request.PdfStreams, request.PageRanges);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validator for MergePdfsCommand.
|
|
/// </summary>
|
|
public class MergePdfsCommandValidator : AbstractValidator<MergePdfsCommand>
|
|
{
|
|
public MergePdfsCommandValidator()
|
|
{
|
|
RuleFor(x => x.PdfStreams)
|
|
.NotNull()
|
|
.WithMessage("PDF streams are required");
|
|
|
|
RuleFor(x => x.PdfStreams)
|
|
.Must(streams => streams != null && streams.Count >= 2)
|
|
.WithMessage("At least 2 PDF files are required for merging");
|
|
}
|
|
}
|