Backend-Arbeitsstand: ERP-Sync, Lieferlebenszyklus, Reports + config.toml

Bringt das Backend vom initialen Skeleton auf den aktuellen Arbeitsstand
(Clean Architecture: domain → application → infrastructure → api).

Wesentliche Bereiche:
- ERP-Anbindung (MSSQL-Pull der Touren, Import-Scheduler, Rückschreiben)
- Lieferlebenszyklus: Scan/Hold/Cancel/Complete, Gutschriften, Notizen,
  Bild-Anhänge, Unterschriften, PDF-Lieferreport → DOCUframe
- Stammdaten: Kunden, Artikel, Lager, Zahlungsarten, Services
- Keycloak-JWT-Gate + Fahrer-Provisionierung via Admin-API
- Admin-API-Key-Gate (X-Admin-Api-Key) für Maschinen-Endpunkte

Jüngste Änderungen dieser Session:
- Belegspezifische Kontaktdaten: alle ERP-Adressen (Beleg-/Liefer-/
  Rechnungsadresse, Ansprechpartner, Kundenstamm) mit Telefon/Mobil/
  E-Mail werden gesynct (Migration 0029, MSSQL-Query, TourDetails)
- Konfiguration von .env (envy/dotenvy) auf config.toml (toml/serde)
  umgestellt; Vorlage config.example.toml, Pfad via HOLZLEITNER_CONFIG

Nicht im Repo (per .gitignore): config.toml (Secrets), data/ (Laufzeit-/
Kundendaten), demo.mp4, .claude/, variocontrol-ai/.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dennis Nemec
2026-06-01 17:52:58 +02:00
parent 438040acce
commit 6a9b5872e1
137 changed files with 13700 additions and 218 deletions

View File

@ -0,0 +1,99 @@
//! Lokaler Dateisystem-Adapter für `SignatureStorage`.
//!
//! Schreibt jede Unterschrift als PNG unter
//! `<base_dir>/<delivery_id>_<role>.png`. Der Pfad ist deterministisch:
//! ein Retry überschreibt dieselbe Datei, statt Müll anzuhäufen. Persistiert
//! wird in der DB nur die relative Referenz (Dateiname), nicht der absolute
//! Pfad — so bleibt ein Umzug des Verzeichnisses unkompliziert.
use std::path::PathBuf;
use async_trait::async_trait;
use uuid::Uuid;
use holzleitner_application::error::ApplicationError;
use holzleitner_application::ports::{SignatureRole, SignatureStorage};
pub struct LocalSignatureStorage {
base_dir: PathBuf,
}
impl LocalSignatureStorage {
/// Legt das Basis-Verzeichnis (rekursiv) an, falls es noch nicht
/// existiert. Ein nicht-anlegbares Verzeichnis ist ein Boot-Fehler.
pub fn new(base_dir: impl Into<PathBuf>) -> std::io::Result<Self> {
let base_dir = base_dir.into();
std::fs::create_dir_all(&base_dir)?;
Ok(Self { base_dir })
}
fn file_name(delivery_id: Uuid, role: SignatureRole) -> String {
format!("{delivery_id}_{}.png", role.as_str())
}
}
#[async_trait]
impl SignatureStorage for LocalSignatureStorage {
async fn save(
&self,
delivery_id: Uuid,
role: SignatureRole,
bytes: Vec<u8>,
) -> Result<String, ApplicationError> {
let name = Self::file_name(delivery_id, role);
let path = self.base_dir.join(&name);
// Blocking-IO bewusst auf einen Blocking-Thread auslagern.
tokio::task::spawn_blocking(move || std::fs::write(&path, &bytes))
.await
.map_err(|e| ApplicationError::Repository(format!("join error: {e}")))?
.map_err(|e| {
ApplicationError::Repository(format!("signatur speichern fehlgeschlagen: {e}"))
})?;
Ok(name)
}
async fn load(&self, reference: &str) -> Result<Option<Vec<u8>>, ApplicationError> {
// Traversal-Schutz: Referenz ist ein einfacher Dateiname.
if reference.contains('/') || reference.contains('\\') || reference.contains("..") {
return Err(ApplicationError::Validation(
"ungültige Signatur-Referenz".into(),
));
}
let path = self.base_dir.join(reference);
let bytes = tokio::task::spawn_blocking(move || std::fs::read(&path))
.await
.map_err(|e| ApplicationError::Repository(format!("join error: {e}")))?;
match bytes {
Ok(b) => Ok(Some(b)),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(None),
Err(e) => Err(ApplicationError::Repository(format!(
"signatur laden fehlgeschlagen: {e}"
))),
}
}
async fn delete_for_delivery(&self, delivery_id: Uuid) -> Result<(), ApplicationError> {
// Beide deterministisch benannten Dateien (Kunde + Fahrer) entfernen.
let paths = [
self.base_dir
.join(Self::file_name(delivery_id, SignatureRole::Customer)),
self.base_dir
.join(Self::file_name(delivery_id, SignatureRole::Driver)),
];
tokio::task::spawn_blocking(move || -> std::io::Result<()> {
for path in paths {
match std::fs::remove_file(&path) {
Ok(()) => {}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
Err(e) => return Err(e),
}
}
Ok(())
})
.await
.map_err(|e| ApplicationError::Repository(format!("join error: {e}")))?
.map_err(|e| {
ApplicationError::Repository(format!("signatur löschen fehlgeschlagen: {e}"))
})
}
}