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:
OlgunR
2026-06-25 16:01:33 +02:00
parent afc0e34312
commit 930b76ecb5
12 changed files with 493 additions and 143 deletions

View File

@@ -1,6 +1,6 @@
# ?? DocumentOperator - Project Roadmap (Feature-Driven Development)
> **Last Updated:** 17.01.2025 | **Status:** In Development | **Current Feature:** Feature 1 - ValidatePDF (Step 1.2 NEXT)
> **Last Updated:** 17.01.2025 | **Status:** In Development | **Current Feature:** Feature 1 - ValidatePDF ? ABGESCHLOSSEN!
---
@@ -44,7 +44,7 @@
| Feature | Type | Status | Swagger Testbar? |
|---------|------|--------|------------------|
| **1. ValidatePDF** | Synchron | ?? In Progress (Step 1.2 NEXT) | ? |
| **1. ValidatePDF** | Synchron | ? Abgeschlossen | ? |
| **2. ExtractAttachments** | Synchron | ? Pending | ? |
| **3. ApplyStamp** | Synchron | ? Pending | ? |
| **4. EmbedCertificate** | Synchron | ? Pending | ? |
@@ -177,66 +177,39 @@ Response: { "pageCount": 5, "fileSizeBytes": 1024, "pdfVersion": "1.4", "hasAtta
---
### ?? Step 1.2: API Layer (Endpoint + Exception Middleware) - **NEXT**
### ? Step 1.2: API Layer (Endpoint + Exception Middleware) - **ABGESCHLOSSEN**
**Ziel:** HTTP Endpoint + zentrale Exception Handling
**Was wird erstellt:**
**Was wurde erstellt:**
#### 1.2.1: Exception Handling Middleware
- **Datei:** `API/Middleware/ExceptionHandlingMiddleware.cs`
- ? **Datei:** `API/Middleware/ExceptionHandlingMiddleware.cs`
- Fängt alle Exceptions
- Mappt zu HTTP Status Codes (400, 404, 500)
- Mappt zu HTTP Status Codes (ValidationException ? 400, DomainValidationException ? 400, NotFoundException ? 404, PdfProcessingException ? 500)
- Gibt RFC 7807 Problem Details zurück
#### 1.2.2: Minimal API Endpoint
- **Datei:** `API/Endpoints/v1/DocumentEndpoints.cs`
```csharp
public static class DocumentEndpoints
{
public static void MapDocumentEndpoints(this IEndpointRouteBuilder app)
{
var group = app.MapGroup("/api/v1/documents")
.WithTags("Documents")
.WithOpenApi();
- ? **Datei:** `API/Endpoints/v1/DocumentEndpoints.cs`
- POST /api/v1/documents/validate
- Nutzt MediatR (ValidatePdfQuery ? ValidatePdfHandler)
- Returns ValidatePdfResponse (200) oder ProblemDetails (400, 500)
group.MapPost("/validate", ValidatePdf)
.WithName("ValidatePdf")
.WithSummary("Validates a PDF document and returns metadata");
}
#### 1.2.3: Infrastructure DependencyInjection
- ? **Datei:** `Infrastructure/DependencyInjection.cs`
- Registriert IPdfProcessor ? DevExpressPdfProcessor
private static async Task<IResult> ValidatePdf(
ValidatePdfRequest request,
IMediator mediator,
CancellationToken ct)
{
var query = new ValidatePdfQuery(Base64String.Create(request.Base64Pdf));
var metadata = await mediator.Send(query, ct);
#### 1.2.4: Program.cs Updates
- ? Application Layer registriert (AddApplication)
- ? Infrastructure Layer registriert (AddInfrastructure)
- ? Exception Middleware registriert (FIRST in pipeline!)
- ? Endpoints registriert (MapDocumentEndpoints)
var response = new ValidatePdfResponse(
metadata.PageCount,
metadata.FileSizeBytes,
metadata.FileSizeMB,
metadata.PdfVersion,
metadata.HasAttachments,
metadata.AttachmentCount
);
return Results.Ok(response);
}
}
```
#### 1.2.3: Program.cs Updates
- Registriert Exception Middleware
- Registriert DocumentEndpoints
- Registriert Application + Infrastructure Services
#### 1.2.4: Integration Tests
- **Datei:** `Tests/Integration/API/DocumentEndpointsTests.cs`
- Test: `POST_ValidatePdf_ValidPdf_Returns200`
- Test: `POST_ValidatePdf_InvalidBase64_Returns400`
- Test: `POST_ValidatePdf_CorruptedPdf_Returns500`
#### 1.2.5: Integration Tests
- ? **Datei:** `Tests/Integration/API/DocumentEndpointsTests.cs`
- ? Test: `POST_ValidatePdf_ValidPdf_Returns200`
- ? Test: `POST_ValidatePdf_InvalidBase64_Returns400`
- ? Test: `POST_ValidatePdf_EmptyPdf_Returns400`
**Akzeptanzkriterien:**
- ? Build erfolgreich
@@ -246,63 +219,70 @@ Response: { "pageCount": 5, "fileSizeBytes": 1024, "pdfVersion": "1.4", "hasAtta
---
### ?? Step 1.3: Swagger Dokumentation
### ? Step 1.3: Swagger Dokumentation - **ABGESCHLOSSEN**
**Ziel:** API-Dokumentation + Swagger UI testbar
**Was wird erstellt:**
**Was wurde erstellt:**
#### 1.3.1: Swagger Configuration
- **Datei:** `API/Configuration/SwaggerConfiguration.cs`
- AddSwaggerGen mit XML Comments
- Konfiguriert API-Versioning
- Fügt Beispiel-Schemas hinzu
- ? **Datei:** `API/Configuration/SwaggerConfiguration.cs`
- `AddSwaggerDocumentation()` Extension Method
- Swagger mit XML Comments konfiguriert
- API-Titel, Version, Beschreibung gesetzt
#### 1.3.2: XML Comments
- Aktivieren in `API/DocumentOperator.API.csproj`:
#### 1.3.2: XML Comments aktiviert
- ? **Datei:** `API/DocumentOperator.API.csproj`
```xml
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
```
- XML Comments für `ValidatePdf` Endpoint:
```csharp
/// <summary>
/// Validates a PDF document and returns metadata
/// </summary>
/// <param name="request">PDF as Base64 string</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>
```
#### 1.3.3: Endpoint dokumentiert
- ? **Datei:** `API/Endpoints/v1/DocumentEndpoints.cs`
- XML Comments für `ValidatePdf` Methode
- Swagger-Annotationen (`.WithSummary()`, `.WithDescription()`, `.Produces<>()`)
#### 1.3.4: DTOs dokumentiert
- ? **Datei:** `Application/Common/DTOs/ValidatePdfRequest.cs`
- XML Comments für Request-Schema
- ? **Datei:** `Application/Common/DTOs/ValidatePdfResponse.cs`
- XML Comments für Response-Schema
- `FileSizeMB` Property hinzugefügt
#### 1.3.5: Program.cs aktualisiert
- ? **Datei:** `API/Program.cs`
- `builder.Services.AddSwaggerDocumentation()` statt `AddSwaggerGen()`
- `using DocumentOperator.API.Configuration;` hinzugefügt
**Akzeptanzkriterien:**
- ? Swagger UI läuft unter `/swagger`
- ? Endpoint `/api/v1/documents/validate` ist sichtbar
- ? Request/Response Schemas sind dokumentiert
- ? Endpoint ist im Swagger UI testbar (manuelle Verifikation!)
- ? Build erfolgreich
- ? Alle Tests grün (11/11 Tests)
- ? XML-Dokumentation wird generiert (`DocumentOperator.API.xml`)
- ? Swagger UI zeigt Endpoint `/api/v1/documents/validate` mit Dokumentation
- ? Request/Response-Schemas sind dokumentiert
- ? Endpoint ist im Swagger UI testbar
---
### ? Feature 1 ABGESCHLOSSEN!
**Was haben wir erreicht?**
- ? ValidatePDF Feature komplett implementiert
- ? Domain ? Infrastructure ? Application ? API ? Tests ? Swagger
- ? ValidatePDF Feature komplett implementiert (Domain ? Infrastructure ? Application ? API ? Tests ? Swagger)
- ? Endpoint ist im Swagger UI testbar
- ? Unit Tests + Integration Tests grün
- ? Unit Tests + Integration Tests grün (11/11)
- ? Clean Architecture eingehalten
- ? TDD angewendet
- ? Swagger-Dokumentation vollständig
**Nächstes Feature:**
? **Feature 2: ExtractAttachments**
---
## ?? FEATURE 2: ExtractAttachments (Synchron) - **PENDING**
## ?? FEATURE 2: ExtractAttachments (Synchron) - **NEXT**
**Was macht dieses Feature?**
- Client sendet PDF als Base64 (JSON)
@@ -897,6 +877,7 @@ DocumentOperator.Tests/
- **Infrastructure Layer:**
- ? IPdfProcessor Interface
- ? DevExpressPdfProcessor.ValidateAsync (mit Tests!)
- ? DependencyInjection.cs (Infrastructure Services)
- **Application Layer:**
- ? DependencyInjection.cs (MediatR + FluentValidation)
@@ -906,15 +887,20 @@ DocumentOperator.Tests/
- ? DTOs (ValidatePdfRequest, ValidatePdfResponse)
- ? Tests (ValidatePdfHandlerTests - 2 Tests grün)
- **API Layer:**
- ? ExceptionHandlingMiddleware.cs (RFC 7807 Problem Details)
- ? DocumentEndpoints.cs (POST /api/v1/documents/validate)
- ? Program.cs (Services + Middleware + Endpoints)
- ? Tests (DocumentEndpointsTests - 3 Tests grün)
### ?? In Progress
- **Feature 1: ValidatePDF**
- ? Step 1.2: API Layer (Endpoint + Exception Middleware) - **NEXT**
- ? Step 1.3: Swagger Dokumentation - **NEXT**
### ? Pending
- **Feature 1: ValidatePDF**
- ? Step 1.2: API Layer (Endpoint + Exception Middleware)
- ? Step 1.3: Swagger Dokumentation
- **Feature 2-5:** ExtractAttachments, ApplyStamp, EmbedCertificate, ConcatenatePDFs
@@ -1004,6 +990,9 @@ DocumentOperator.Tests/
| 17.01.2025 | **ROADMAP** | ?? **Komplett umstrukturiert** (Feature-Driven Development!) |
| 17.01.2025 | **PHASENPLAN** | ?? **Komplett umstrukturiert** (Feature-basiert + Datum korrigiert) |
| 17.01.2025 | **Feature 1 - Step 1.1** | ? **ABGESCHLOSSEN** - Application Layer (MediatR, Behaviors, ValidatePDF Feature, DTOs, Tests) |
| 17.01.2025 | **Feature 1 - Step 1.2** | ? **ABGESCHLOSSEN** - API Layer (ExceptionMiddleware, Endpoint, Program.cs, Integration Tests - 3/3 grün) |
| 17.01.2025 | **Feature 1 - Step 1.3** | ? **ABGESCHLOSSEN** - Swagger Dokumentation (SwaggerConfiguration, XML Comments, Endpoint/DTO-Dokumentation - 11/11 Tests grün) |
| 17.01.2025 | **Feature 1** | ? **KOMPLETT ABGESCHLOSSEN** - ValidatePDF Feature testbar im Swagger UI! |
---