Add ValidatePDF feature with API, Swagger, and tests
Implemented the ValidatePDF feature end-to-end: - Added `/api/v1/documents/validate` Minimal API endpoint. - Introduced centralized ExceptionHandlingMiddleware. - Configured Swagger with `AddSwaggerDocumentation` extension. - Enabled XML comments in `DocumentOperator.API.csproj`. - Updated DTOs with XML comments and added `FileSizeMB`. - Added integration tests for the ValidatePDF endpoint (3 tests). - Registered infrastructure services (e.g., `IPdfProcessor`). - Refactored `Program.cs` to include middleware and endpoints. - Updated PHASENPLAN.md and ROADMAP.md to reflect progress. - Cleaned up code and made `Program` accessible for tests.
This commit is contained in:
@@ -1,6 +1,67 @@
|
||||
namespace DocumentOperator.API.Endpoints.v1
|
||||
using DocumentOperator.Application.Common.DTOs;
|
||||
using DocumentOperator.Application.Features.Documents.ValidatePdf;
|
||||
using DocumentOperator.Domain.Models.ValueObjects;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DocumentOperator.API.Endpoints.v1;
|
||||
|
||||
/// <summary>
|
||||
/// Document endpoints (Minimal API)
|
||||
/// </summary>
|
||||
public static class DocumentEndpoints
|
||||
{
|
||||
public class DocumentEndpoints
|
||||
/// <summary>
|
||||
/// Maps all document-related endpoints
|
||||
/// </summary>
|
||||
public static void MapDocumentEndpoints(this IEndpointRouteBuilder app)
|
||||
{
|
||||
var group = app.MapGroup("/api/v1/documents")
|
||||
.WithTags("Documents");
|
||||
|
||||
// POST /api/v1/documents/validate
|
||||
group.MapPost("/validate", ValidatePdf)
|
||||
.WithName("ValidatePdf")
|
||||
.WithSummary("Validates a PDF document and returns metadata")
|
||||
.WithDescription("Validates the PDF format and extracts metadata (page count, file size, PDF version, attachments)")
|
||||
.Produces<ValidatePdfResponse>(StatusCodes.Status200OK)
|
||||
.Produces<ProblemDetails>(StatusCodes.Status400BadRequest)
|
||||
.Produces<ProblemDetails>(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates a PDF document and returns metadata
|
||||
/// </summary>
|
||||
/// <param name="request">PDF as Base64 string</param>
|
||||
/// <param name="mediator">MediatR instance</param>
|
||||
/// <param name="cancellationToken">Cancellation token</param>
|
||||
/// <returns>PDF metadata (page count, file size, etc.)</returns>
|
||||
/// <response code="200">PDF is valid, metadata returned</response>
|
||||
/// <response code="400">Invalid PDF or Base64 format</response>
|
||||
/// <response code="500">Internal server error during validation</response>
|
||||
private static async Task<IResult> ValidatePdf(
|
||||
ValidatePdfRequest request,
|
||||
IMediator mediator,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// DTO → Query (Value Objects erstellen - kann DomainValidationException werfen!)
|
||||
var query = new ValidatePdfQuery(
|
||||
Base64String.Create(request.Base64Pdf)
|
||||
);
|
||||
|
||||
// MediatR Handler aufrufen (ValidationBehavior → Handler)
|
||||
var metadata = await mediator.Send(query, cancellationToken);
|
||||
|
||||
// PdfMetadata → Response DTO
|
||||
var response = new ValidatePdfResponse(
|
||||
metadata.PageCount,
|
||||
metadata.FileSizeBytes,
|
||||
metadata.FileSizeMB,
|
||||
metadata.PdfVersion,
|
||||
metadata.HasAttachments,
|
||||
metadata.AttachmentCount
|
||||
);
|
||||
|
||||
return Results.Ok(response);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user