Initial commit with inital CMS
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
# Controller Design — Unit 03: Availability Module
|
||||
|
||||
Dit document beschrijft de endpoints van de `AvailabilityController`.
|
||||
|
||||
## 1. Publieke Status Endpoint
|
||||
|
||||
- **Method**: `GET`
|
||||
- **Path**: `/api/availability/status`
|
||||
- **Auth**: Geen (AllowAnonymous)
|
||||
- **Response**: `AvailabilityResponse`
|
||||
- **Logic**: Roept `IAvailabilityService.IsAvailableAsync()` aan en mapt de status naar het response object.
|
||||
|
||||
## 2. Status Update Endpoint (Beheer)
|
||||
|
||||
- **Method**: `POST`
|
||||
- **Path**: `/api/availability/admin/status`
|
||||
- **Auth**: `OwnerOnly` Policy (Unit 02)
|
||||
- **Request Body**:
|
||||
```json
|
||||
{
|
||||
"newStatus": "Maintenance",
|
||||
"reason": "Gepland database onderhoud"
|
||||
}
|
||||
```
|
||||
- **Logic**:
|
||||
1. Valideert de nieuwe status.
|
||||
2. Werkt de database record bij via de `IAvailabilityService`.
|
||||
3. Maakt een audit log aan (Unit 02).
|
||||
- **Response**: `200 OK`.
|
||||
|
||||
## 3. Integratie met Audit Log
|
||||
|
||||
Bij elke statuswijziging wordt de `IAuditService` aangeroepen met de volgende gegevens:
|
||||
- **ActorId**: De ID van de Owner.
|
||||
- **Action**: `SystemStatusChanged`.
|
||||
- **Details**: `OldStatus: Available, NewStatus: Maintenance, Reason: ...`
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
# Middleware Design — Unit 03: Availability Module
|
||||
|
||||
Dit document beschrijft de technische implementatie van de Availability Middleware.
|
||||
|
||||
## 1. Middleware Registratie
|
||||
|
||||
De middleware wordt in de `Program.cs` van de API Shell (U04) geregistreerd:
|
||||
|
||||
```csharp
|
||||
app.UseExceptionHandler(); // Eerst de exception handler (U01)
|
||||
app.UseAvailability(); // Daarna de availability check
|
||||
// ... andere middleware (Auth, Routing, etc)
|
||||
```
|
||||
|
||||
## 2. AvailabilityMiddleware Logica
|
||||
|
||||
- **Bypass voor Status Endpoint**: Het pad `/api/availability/status` wordt altijd doorgelaten zonder check.
|
||||
- **Check Fase**:
|
||||
- De middleware roept `IAvailabilityService.IsAvailableAsync()` aan.
|
||||
- Indien status == `Available` -> `_next(context)`.
|
||||
- **Bypass voor Admins/Owners**:
|
||||
- Indien status == `Maintenance` of `NotAvailable`:
|
||||
- De middleware inspecteert het JWT token in de `Authorization` header handmatig (omdat de globale Authentication middleware nog niet is uitgevoerd op dit punt).
|
||||
- Indien de claim `role` gelijk is aan `Owner` of `Administrator` -> `_next(context)`.
|
||||
- Anders -> Retourneer `503 Service Unavailable` met `ApiErrorResponse`.
|
||||
|
||||
## 3. PersistentAvailabilityService
|
||||
|
||||
Implementatie van de interface uit Unit 01.
|
||||
|
||||
- **Database Opslag**: Maakt gebruik van de `ApplicationDbContext` (Unit 02).
|
||||
- **Circuit Breaker**:
|
||||
- Houdt in een statische variabele de `_lastErrorTime` en `_cachedStatus` bij.
|
||||
- Indien `DateTimeOffset.UtcNow - _lastErrorTime < 30 seconden` -> Retourneer de `_cachedStatus` (default: `Available`) zonder de database te pollen.
|
||||
- **Logging**: Elke blokkade wordt gelogd met het IP-adres van de client en het gevraagde pad.
|
||||
Reference in New Issue
Block a user