Initial: Rust-Backend mit Clean Architecture (domain/application/infrastructure/api)
Vier-Crate-Workspace mit:
- Domain: Account, Car, Tour, Delivery, DeliveryItem, DeliveryNote, Customer,
Article, Warehouse, ScanState, AuditAction — alle mit serde + feature-gated
utoipa::ToSchema.
- Application: Ports (TourRepository, DeliveryRepository, ScanRepository,
DeliveryNoteRepository, CarRepository, AuthService) und Use Cases.
- Infrastructure: Postgres-Adapter via sqlx (PgTourRepository etc.) +
Keycloak-AuthService mit JWKS-Cache + OIDC-Discovery.
- API: Axum 0.8, utoipa-OpenAPI + Swagger-UI, JWT-Bearer-Middleware,
AuthenticatedUser-Extractor.
Endpoints:
- GET /me/tours/today, /tours/{id}, /accounts/{pn}, /me/cars, /health
- POST /sync/tour, /scans (bulk + idempotent via clientScanId),
/deliveries/{id}/{hold,resume,cancel,complete,notes}, /me/cars
- PUT /tours/{id}/delivery-order, /deliveries/{id}/assigned-car, /me/cars/{id}
- PATCH /me/cars/{id}
Datenmodell:
- 6 Migrationen (accounts, tours/deliveries/items + Stammdaten,
scan_audit mit clientScanId-UNIQUE, state_reason refactor,
delivery_notes, cars + FKs nachziehen).
- Business-stabile Beleg-Keys (belegart_id, belegnummer) für ERP-Sync.
- Append-only scan_audit + embedded scan_state als doppelte Wahrheit.
Dev-Setup:
- docker-compose mit Postgres 17 + Keycloak 26
- Keycloak-Realm 'holzleitner' mit Public-Client (PKCE), Testfahrer
(PN 1001) + Audience-/Personalnummer-Mapper
This commit is contained in:
49
crates/api/src/routes/scans.rs
Normal file
49
crates/api/src/routes/scans.rs
Normal file
@ -0,0 +1,49 @@
|
||||
use axum::Json;
|
||||
use axum::Router;
|
||||
use axum::extract::State;
|
||||
use axum::routing::post;
|
||||
use holzleitner_application::dto::{ApplyScansRequest, ApplyScansResponse};
|
||||
|
||||
use crate::error::ApiError;
|
||||
use crate::extractors::AuthenticatedUser;
|
||||
use crate::state::AppState;
|
||||
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new().route("/scans", post(apply_scans))
|
||||
}
|
||||
|
||||
/// Wendet eine Liste von Scan-Events idempotent an.
|
||||
///
|
||||
/// Pro Event ein eigenes Resultat. Status `applied` schreibt einen
|
||||
/// frischen Audit-Eintrag, `duplicate` liefert den aktuellen Stand am
|
||||
/// Server, `rejected` enthält die Begründung. Reihenfolge der `results`
|
||||
/// entspricht der Reihenfolge der `scans` im Request.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/scans",
|
||||
tag = "scans",
|
||||
request_body = ApplyScansRequest,
|
||||
responses(
|
||||
(status = 200, description = "Bulk-Ergebnis pro Event", body = ApplyScansResponse),
|
||||
(status = 401, description = "Authentifizierung fehlgeschlagen")
|
||||
),
|
||||
security(
|
||||
("bearer_auth" = [])
|
||||
)
|
||||
)]
|
||||
pub async fn apply_scans(
|
||||
State(state): State<AppState>,
|
||||
AuthenticatedUser(claims): AuthenticatedUser,
|
||||
Json(request): Json<ApplyScansRequest>,
|
||||
) -> Result<Json<ApplyScansResponse>, ApiError> {
|
||||
tracing::info!(
|
||||
actor = claims.personalnummer,
|
||||
count = request.scans.len(),
|
||||
"apply_scans",
|
||||
);
|
||||
let response = state
|
||||
.apply_scans
|
||||
.execute(request, claims.personalnummer)
|
||||
.await?;
|
||||
Ok(Json(response))
|
||||
}
|
||||
Reference in New Issue
Block a user