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:
53
crates/application/src/usecases/set_delivery_order.rs
Normal file
53
crates/application/src/usecases/set_delivery_order.rs
Normal file
@ -0,0 +1,53 @@
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::dto::{SetDeliveryOrderRequest, SetDeliveryOrderResponse};
|
||||
use crate::error::ApplicationError;
|
||||
use crate::ports::TourRepository;
|
||||
|
||||
/// Schreibt die Sortier-Reihenfolge aller Lieferungen einer Tour neu.
|
||||
///
|
||||
/// Eingabe-Validierung (vor DB-Aufruf):
|
||||
/// * mindestens eine Id
|
||||
/// * keine Duplikate
|
||||
///
|
||||
/// Die Mengen-Übereinstimmung mit der Tour wird in der Persistence
|
||||
/// geprüft (braucht DB-Kontext).
|
||||
pub struct SetDeliveryOrderUseCase {
|
||||
repository: Arc<dyn TourRepository>,
|
||||
}
|
||||
|
||||
impl SetDeliveryOrderUseCase {
|
||||
pub fn new(repository: Arc<dyn TourRepository>) -> Self {
|
||||
Self { repository }
|
||||
}
|
||||
|
||||
pub async fn execute(
|
||||
&self,
|
||||
tour_id: Uuid,
|
||||
request: SetDeliveryOrderRequest,
|
||||
) -> Result<SetDeliveryOrderResponse, ApplicationError> {
|
||||
if request.delivery_ids.is_empty() {
|
||||
return Err(ApplicationError::Validation(
|
||||
"delivery_ids darf nicht leer sein".into(),
|
||||
));
|
||||
}
|
||||
let mut seen = HashSet::with_capacity(request.delivery_ids.len());
|
||||
for id in &request.delivery_ids {
|
||||
if !seen.insert(*id) {
|
||||
return Err(ApplicationError::Validation(format!(
|
||||
"delivery_id {id} kommt mehrfach vor"
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
let order = self
|
||||
.repository
|
||||
.set_delivery_order(tour_id, &request.delivery_ids)
|
||||
.await?;
|
||||
|
||||
Ok(SetDeliveryOrderResponse { tour_id, order })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user