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.
212 lines
8.5 KiB
C#
212 lines
8.5 KiB
C#
using DocumentService.Application.ConvertFromPdfA;
|
|
using DocumentService.Application.ConvertToPdfA;
|
|
using DocumentService.Domain.Common.Exceptions;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace DocumentService.API.Controllers;
|
|
|
|
/// <summary>
|
|
/// Controller for PDF conversion operations (PDF ? PDF/A)
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/pdf/conversion")]
|
|
[Obsolete("This endpoint is not implemented yet.")]
|
|
public class PdfConversionController(IMediator mediator) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Converts a standard PDF to PDF/A format.
|
|
/// Supports multipart/form-data file upload.
|
|
/// </summary>
|
|
/// <param name="file">The PDF file to convert</param>
|
|
/// <param name="pdfALevel">Target PDF/A level (e.g., "PDF/A-1b", "PDF/A-2b", "PDF/A-3b")</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>PDF/A compliant document</returns>
|
|
/// <response code="200">PDF converted to PDF/A successfully</response>
|
|
/// <response code="400">Invalid input (file missing, not a PDF, or invalid PDF/A level)</response>
|
|
/// <response code="500">Internal server error during PDF processing</response>
|
|
[Obsolete("This endpoint is not implemented yet.")]
|
|
[HttpPost("to-pdfa")]
|
|
[Consumes("multipart/form-data")]
|
|
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
|
public async Task<IActionResult> ConvertToPdfAFromFile(
|
|
IFormFile file,
|
|
[FromQuery] string pdfALevel = "PDF/A-3b",
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
if (file == null || file.Length == 0)
|
|
{
|
|
throw new BadRequestException("PDF file is required");
|
|
}
|
|
|
|
// Use IFormFile stream directly (no intermediate byte[] conversion)
|
|
using var pdfStream = file.OpenReadStream();
|
|
|
|
// Send command to MediatR
|
|
var command = new ConvertToPdfACommand
|
|
{
|
|
PdfStream = pdfStream,
|
|
PdfALevel = pdfALevel
|
|
};
|
|
byte[] resultPdf = await mediator.Send(command, cancellationToken);
|
|
|
|
// Return PDF/A file
|
|
return File(resultPdf, "application/pdf", "converted-pdfa.pdf");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a standard PDF to PDF/A format.
|
|
/// Supports Base64-encoded PDF via JSON payload.
|
|
/// </summary>
|
|
/// <param name="request">Request containing Base64-encoded PDF and PDF/A level</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>PDF/A compliant document</returns>
|
|
/// <response code="200">PDF converted to PDF/A successfully</response>
|
|
/// <response code="400">Invalid input (Base64 format error, not a PDF, or invalid PDF/A level)</response>
|
|
/// <response code="500">Internal server error during PDF processing</response>
|
|
[Obsolete("This endpoint is not implemented yet.")]
|
|
[HttpPost("to-pdfa")]
|
|
[Consumes("application/json")]
|
|
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
|
public async Task<IActionResult> ConvertToPdfAFromBase64(
|
|
[FromBody] ConvertToPdfARequest request,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
// Convert Base64 PDF to stream
|
|
byte[] pdfBytes;
|
|
try
|
|
{
|
|
pdfBytes = Convert.FromBase64String(request.Base64Pdf);
|
|
}
|
|
catch (FormatException ex)
|
|
{
|
|
throw new BadRequestException("Invalid Base64 PDF format: " + ex.Message);
|
|
}
|
|
|
|
using var pdfStream = new MemoryStream(pdfBytes);
|
|
|
|
// Send command to MediatR
|
|
var command = new ConvertToPdfACommand
|
|
{
|
|
PdfStream = pdfStream,
|
|
PdfALevel = request.PdfALevel ?? "PDF/A-3b"
|
|
};
|
|
byte[] resultPdf = await mediator.Send(command, cancellationToken);
|
|
|
|
// Return PDF/A file
|
|
return File(resultPdf, "application/pdf", "converted-pdfa.pdf");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a PDF/A document to a standard PDF (removes PDF/A restrictions).
|
|
/// Supports multipart/form-data file upload.
|
|
/// </summary>
|
|
/// <param name="file">The PDF/A file to convert</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Standard PDF document</returns>
|
|
/// <response code="200">PDF/A converted to standard PDF successfully</response>
|
|
/// <response code="400">Invalid input (file missing, not a PDF)</response>
|
|
/// <response code="500">Internal server error during PDF processing</response>
|
|
[Obsolete("This endpoint is not implemented yet.")]
|
|
[HttpPost("from-pdfa")]
|
|
[Consumes("multipart/form-data")]
|
|
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
|
public async Task<IActionResult> ConvertFromPdfAFromFile(
|
|
IFormFile file,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
if (file == null || file.Length == 0)
|
|
{
|
|
throw new BadRequestException("PDF/A file is required");
|
|
}
|
|
|
|
// Use IFormFile stream directly (no intermediate byte[] conversion)
|
|
using var pdfStream = file.OpenReadStream();
|
|
|
|
// Send command to MediatR
|
|
var command = new ConvertFromPdfACommand { PdfStream = pdfStream };
|
|
byte[] resultPdf = await mediator.Send(command, cancellationToken);
|
|
|
|
// Return standard PDF file
|
|
return File(resultPdf, "application/pdf", "converted-pdf.pdf");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a PDF/A document to a standard PDF (removes PDF/A restrictions).
|
|
/// Supports Base64-encoded PDF via JSON payload.
|
|
/// </summary>
|
|
/// <param name="request">Request containing Base64-encoded PDF/A</param>
|
|
/// <param name="cancellationToken">Cancellation token</param>
|
|
/// <returns>Standard PDF document</returns>
|
|
/// <response code="200">PDF/A converted to standard PDF successfully</response>
|
|
/// <response code="400">Invalid input (Base64 format error, not a PDF)</response>
|
|
/// <response code="500">Internal server error during PDF processing</response>
|
|
[Obsolete("This endpoint is not implemented yet.")]
|
|
[HttpPost("from-pdfa")]
|
|
[Consumes("application/json")]
|
|
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
|
public async Task<IActionResult> ConvertFromPdfAFromBase64(
|
|
[FromBody] ConvertFromPdfARequest request,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
// Convert Base64 PDF to stream
|
|
byte[] pdfBytes;
|
|
try
|
|
{
|
|
pdfBytes = Convert.FromBase64String(request.Base64Pdf);
|
|
}
|
|
catch (FormatException ex)
|
|
{
|
|
throw new BadRequestException("Invalid Base64 PDF format: " + ex.Message);
|
|
}
|
|
|
|
using var pdfStream = new MemoryStream(pdfBytes);
|
|
|
|
// Send command to MediatR
|
|
var command = new ConvertFromPdfACommand { PdfStream = pdfStream };
|
|
byte[] resultPdf = await mediator.Send(command, cancellationToken);
|
|
|
|
// Return standard PDF file
|
|
return File(resultPdf, "application/pdf", "converted-pdf.pdf");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Request DTO for converting PDF to PDF/A
|
|
/// </summary>
|
|
public record ConvertToPdfARequest
|
|
{
|
|
/// <summary>
|
|
/// PDF document encoded as Base64 string
|
|
/// </summary>
|
|
/// <example>JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c...</example>
|
|
public required string Base64Pdf { get; init; }
|
|
|
|
/// <summary>
|
|
/// Target PDF/A level (default: "PDF/A-3b")
|
|
/// </summary>
|
|
/// <example>PDF/A-3b</example>
|
|
public string? PdfALevel { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Request DTO for converting PDF/A to PDF
|
|
/// </summary>
|
|
public record ConvertFromPdfARequest
|
|
{
|
|
/// <summary>
|
|
/// PDF/A document encoded as Base64 string
|
|
/// </summary>
|
|
/// <example>JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c...</example>
|
|
public required string Base64Pdf { get; init; }
|
|
}
|