Commit graph

238 commits

Author SHA1 Message Date
Jens Reinemann
75cfc41924 fix(websocket): Reconnect-Strategie robuster machen
WebSocketClientImpl:
- Jitter (±25%) zum exponentiellen Backoff hinzugefügt, um
  Thundering-Herd-Effekt bei Server-Neustart zu vermeiden
- Retry-Zähler mit MAX_RETRIES=5: nach 5 konsekutiven Fehlschlägen
  wird ConnectionFailed-Event emittiert (nach ~62s)
- Client versucht weiterhin im MAX_BACKOFF-Intervall (60s) zu
  reconnecten, gibt nicht vollständig auf
- Zähler wird bei erfolgreicher Verbindung zurückgesetzt

WebSocketEvent: neues ConnectionFailed(message) Event hinzugefügt

SettingsViewModel: ConnectionFailed -> SyncStatus.Error,
Connected -> SyncStatus.Idle (Fehler wird beim Reconnect gelöscht)

Closes #73
2026-05-17 03:00:51 +02:00
Jens Reinemann
eb5bdd4b7b feat(security): JWT-Tokens in EncryptedSharedPreferences speichern
Sensitive Keys (auth_access_token, auth_refresh_token, auth_username,
auth_user_id, openai_api_key) werden jetzt ueber EncryptedSharedPreferences
gespeichert statt als Klartext in der Room-Settings-Tabelle.

Neue Dateien:
- SecureTokenStorage: Interface fuer sichere Key-Value-Speicherung
- EncryptedPrefsTokenStorage: Implementierung mit AndroidX Security Crypto
- SecurityModule: Hilt-Provider fuer SecureTokenStorage

Aenderungen:
- SettingsKeys: SENSITIVE_KEYS Set definiert welche Keys verschluesselt werden
- SettingsRepositoryImpl: Routet sensitive Keys an SecureTokenStorage,
  nicht-sensitive weiterhin an Room DAO
- ImportExportRepositoryImpl: Filtert sensitive Keys bei Export und Import
- SettingsRepositoryImplTest: 4 neue Tests fuer Secure-Storage-Routing

Closes #72
2026-05-17 02:55:43 +02:00
Jens Reinemann
90580ecb3e refactor(room): fallbackToDestructiveMigration entfernen und Migrationstests vervollständigen
Migrations.kt: KDoc für MIGRATION_2_3 und MIGRATION_3_4 ergänzt.
KrisenvorratDatabaseMigrationTest: MIGRATION_3_4 in alle Testhelfer
aufgenommen, createV3Database() + openMigratedDbV4() hinzugefügt,
Tests für v3→v4 (messages-Tabelle) und v1→v4 Full-Path-Migration
ergänzt. freshInstall-Test registriert jetzt alle Migrationen.
docs/migration-guide.md: Entwickler-Leitfaden mit Checkliste,
SQLite-Einschränkungen und Testanleitung.

fallbackToDestructiveMigration() war bereits entfernt; dieses Ticket
stellt sicher, dass alle Migrationspfade getestet und dokumentiert sind.

Closes #71
2026-05-17 02:40:20 +02:00
Jens Reinemann
f792213b1e refactor(server): H2 durch PostgreSQL ersetzen
- DatabaseFactory: HikariCP Connection-Pool fuer PostgreSQL (10 Connections,
  REPEATABLE_READ), H2 weiterhin ohne Pool (fuer Tests)
- Dependencies: postgresql-Treiber + HikariCP hinzugefuegt, H2 nur noch
  testImplementation
- Migration-SQL: uppercase Tabellennamen auf lowercase normalisiert
  (dialect-agnostisch fuer H2 und PostgreSQL)
- docker-compose.yml: PostgreSQL 17 + Krisenvorrat-Server mit DB-Env-Vars
- Env-Var-Konfiguration: KRISENVORRAT_DB_URL, _DB_USER, _DB_PASSWORD,
  _DB_DRIVER (Defaults auf PostgreSQL localhost)
- Alle 554 Tests gruen (H2 in-memory fuer Tests beibehalten)

Closes #70
2026-05-17 02:35:08 +02:00
Jens Reinemann
033b0fae61 feat(server): Statistik-Kacheln auf Admin-Inventarübersicht
- InventoryStatsDto: neues DTO mit totalItems, totalLocations,
  totalCategories, lastUpdated, recentTransactions
- InventoryRepository.getAggregatedStats(): Aggregierte Statistiken
  über alle Inventare (COUNT, MAX, 30-Tage-Filter)
- AdminRoutes: GET /api/admin/stats Endpoint (admin-only)
- Admin-UI: Stats-Grid mit 5 Kacheln (Artikel, Orte, Kategorien,
  Änderungen 30 Tage, letzte Änderung) oben auf der Übersichtsseite
- 7 neue Tests: 4 Endpoint-Tests (InventoryStatsTest),
  3 Repository-Tests (getAggregatedStats)
- Alle 87 Tests grün

Closes #68
2026-05-17 02:19:18 +02:00
Jens Reinemann
549e4c916e feat(server): PATCH /api/inventory/items/{id} auf partielles Update umstellen
- Route empfängt JsonObject statt ItemDto, nur übergebene Felder werden aktualisiert
- validatePartialItem() validiert nur vorhandene Felder (name, unit, expiryDate)
- patchItemPartial() im Repository: Guard für leere Felder, kein SQL-Update wenn nichts zu ändern
- Response liefert das aktualisierte Item aus der DB (loadItem) statt des Inputs
- Bestehende Tests in InputValidationTest angepasst (senden nun partielle JSON-Bodys)
- Neue PatchItemTest-Klasse: 10 Tests (Happy Path, 404, Auth, Validierung, Persistenz)
- Alle 554 Tests grün

Closes #56
2026-05-17 02:13:24 +02:00
Jens Reinemann
4b1a5818f2 feat(chat): UTF-8-Unterstützung für Umlaute und Emoji-Eingabe
Closes #66

Server (Serialization.kt):
- ContentNegotiation explizit mit charset=UTF-8 konfiguriert, damit
  Response-Header immer 'application/json; charset=utf-8' enthält

App (ChatScreen.kt):
- Emoji-Button (Face-Icon) zur MessageInputBar hinzugefügt, der bei Klick
  den Fokus auf das Eingabefeld setzt und die Soft-Keyboard öffnet (System-
  IME mit Emoji-Panel-Zugang)
- FocusRequester + LocalSoftwareKeyboardController integriert

Tests:
- Utf8MessagingTest (Server): 6 Tests für Umlaute, Emojis, Multi-Codepoint-
  Emojis, gemischte Nachrichten, Konversationsabruf, charset-Header
- ChatViewModelTest (App): 4 neue Tests für Umlaut-, Emoji- und gemischte
  Nachrichten
- run-integration-tests.ps1: Szenario 6a mit 5 Testfällen (Umlaute, Emojis,
  gemischt, Konversation, WebSocket-Delivery mit UTF-8)
2026-05-17 01:58:27 +02:00
Jens Reinemann
95e262d009 chore: Backlog-Status in Board-Skripten ergaenzen
- set-board-status.ps1: 'Backlog' (4ce6ee37) als gueltigen Status erganzt
- create-next-ticket.ps1: -Status Parameter (Todo|Backlog, Default: Todo)
  Todo: Order = min - 1 (naechstes Ticket)
  Backlog: Order = max + 10 (ans Ende gestellt)
  Explizite Status-Setzung via gh project item-edit nach Board-Add
2026-05-17 01:51:18 +02:00
Jens Reinemann
d354e3b37c security: Server-seitige Input-Validierung & Body-Size-Limit (#67)
- Routing.kt: Content-Length-Intercept (max 1 MB, HTTP 413)
- InventoryRoutes.kt: String-Längen (name ≤255, unit ≤50, id ≤36,
  category/location ≤255, setting key ≤255), expiryDate-Regex
  YYYY-MM-DD, Array-Limits (items ≤10000, categories/locations ≤500)
- AdminRoutes.kt: username-Länge ≤255
- InputValidationTest.kt: 16 neue negative Tests, alle 532 Tests grün
2026-05-17 01:20:49 +02:00
Jens Reinemann
26b50eea36 test: Szenario 6 Bob-Generaltest in run-integration-tests.ps1
- Haupt-Szenario: Login, PUT 10 Items (3 Kat, 2 Lagerorte), PATCH qty,
  PUT 11 Items (Salzcracker), WS inventoryUpdated, WS fullSyncRequired
- T1: PATCH unbekannte ID -> 404
- T2: PUT leer -> 0 Items
- T3: Zwei PUTs -> zweites ueberschreibt
- T4: Bob patcht selbst -> WS-Event
- T5: Bob/Alice getrennte Inventare
- T6: Ungueltiger Token -> 401
- T7: Zwei WS-Sessions -> beide empfangen Events
- T8: PATCH nach Disconnect -> kein Server-Fehler
- Fix: Receive-WsMessages mit return ,\ (PS-Array-Unwrapping)
- Fix: @()-Wrapping fuer Where-Object-Filter (1-Element-Ergebnis)
Ergebnis: 30/30 Tests bestanden
2026-05-17 01:01:29 +02:00
Jens Reinemann
2555a942ec fix: Server-App WebSocket-Kompatibilität und DELETE-Route
- WebSocketManager: inventory_updated -> inventoryUpdated,
  full_sync_required -> fullSyncRequired (camelCase wie App erwartet)
- InventoryRoutes: DELETE /api/inventory/items/{id} hinzugefügt
- InventoryRepository: deleteItem(inventoryId, itemId) implementiert
2026-05-17 00:42:03 +02:00
Jens Reinemann
2d4ebd63b0 fix(server): Code-Review-Korrekturen Inventory Sharing
- UserRow: inventoryId-Feld ergaenzt
- AdminRoutes: Delete nutzt findById() statt listAll().find{}
- AdminRoutes: PUT/POST inventory/new geben 404 wenn User nicht existiert
- index.html: Doppelten alten HTML-Content entfernt (277 Zeilen)
2026-05-17 00:35:15 +02:00
Jens Reinemann
c03475e7e5 feat(server): Inventory Sharing – User:Inventory N:1
- Inventories-Tabelle neu: id, created_at
- Users.inventory_id FK → Inventories
- Items/Categories/Locations/Settings: user_id → inventory_id
- DatabaseFactory: Schema-Migration + Data-Migration (user_id→inventory_id)
- InventoryRepository: getEffectiveInventoryId(), createInventory(),
  assignUserToInventory(), cleanupOrphanedInventory(),
  listInventoriesWithUsers(); alle Ops auf inventoryId umgestellt
- UserRepository.create(): legt automatisch neues Inventory an
- InventoryRoutes: löst inventoryId via getEffectiveInventoryId()
- AdminRoutes: PUT /users/{id}/inventory (zuweisen),
  POST /users/{id}/inventory/new (trennen), GET /admin/inventories
- Admin-UI: Inventar-Spalte, 'Inventar wechseln'-Modal, 'Neues
  Inventar'-Button, Inventar-Übersicht (gruppiert)
- InventorySharingTest: 8 neue Integrationstests (Sharing, Isolation,
  Cleanup, Berechtigungen)
- Alle 48 Server-Tests gruen (inkl. bestehende Tests unveraendert)
2026-05-17 00:30:06 +02:00
Jens Reinemann
8576fffdb7 style: run-integration-tests.ps1 Formatierung angleichen 2026-05-17 00:12:19 +02:00
Jens Reinemann
6bed1214c5 test: Integration-Test-Suite fuer Server (Auth, Sync, Messaging, WS)
run-integration-tests.ps1:
- Szenario 1: Auth-Flow (Alice + Bob Login, Token-Validierung)
- Szenario 2: Inventory Sync (PUT, GET, PATCH/items/{id})
- Szenario 3: Messaging + Offline-Delivery (WS-Push nach Reconnect)
- Szenario 4: JWT Refresh (neuer Access-Token bleibt gueltig)
- Szenario 5: Parallele Sessions (Server erkennt Online-Status korrekt)
Alle 15 Tests bestanden gegen VPS-Server (195.246.231.210:8080)
Closes #60
2026-05-17 00:08:35 +02:00
Jens Reinemann
56ac9b1425 feat: Messaging-System mit Offline-First und WebSocket-Push (#58)
## Server
- Messages-Tabelle (id, sender_id, receiver_id, body, sent_at, delivered_at)
- MessageRepository: save/getUndelivered/getConversation/markDelivered (JOIN statt N+1)
- POST /api/messages, GET /api/messages/{userId}: Nachrichten senden/abrufen
- GET /api/users: User-Liste fuer authentifizierte User (ohne eigenen Account)
- WebSocketManager: notifyNewMessage() + isOnline()
- WebSocketRoutes: unzugestellte Nachrichten bei Reconnect pushen
- LoginResponse: userId + username ergaenzt
- Server-Dependency: kotlinx.serialization fuer shared

## App
- MessageEntity + MessageDao (Room, Migration 3->4)
- KrisenvorratDatabase v4, Migrations.MIGRATION_3_4
- MessageRepositoryImpl: Offline-First (isPending), drain bei WebSocket-Connect
- WebSocketEvent.NewMessage -> MessageDto aus shared
- WebSocketClientImpl: new_message-Event parsen
- AUTH_USER_ID in SettingsKeys, SyncServiceImpl speichert userId bei Login
- UserListScreen + UserListViewModel: User-Liste anzeigen
- ChatScreen + ChatViewModel: WhatsApp-Style Chat (links/rechts, Zeitstempel)
- Navigation: Screen.UserList, Screen.Chat, MESSAGES in Bottom-Nav
- RepositoryModule: MessageRepository gebunden

## Tests
- 234 Tests, 0 Fehler
2026-05-16 23:35:25 +02:00
Jens Reinemann
1d7a62448a feat: Offline-Queue, Sofort-Sync & Last-Write-Wins (#61)
- PendingSyncOpEntity + PendingSyncOpDao: Room-Queue fuer ausstehende PATCH/DELETE-Ops
- MIGRATION_2_3: neue Tabelle pending_sync_ops (Version 2 -> 3)
- SyncService.patchItem() + deleteItem(): PATCH/DELETE /api/inventory/items/{id}
- ItemRepositoryImpl: nach insert/update/delete sofortiger PATCH-Versuch (fire-and-forget),
  bei Netzwerkfehler (Timeout/Connection/Unknown) -> Queue, AuthError/NotConfigured -> silent
- drainQueue() bei WebSocketEvent.Connected: Queue abarbeiten, korrupte Ops loeschen
- ImportExportRepositoryImpl.applyInventoryDto(): Last-Write-Wins per lastUpdated-Timestamp
- KrisenvorratDatabaseMigrationTest: V2->V3-Test ergaenzt
- 223 Unit Tests gruen
2026-05-16 21:40:10 +02:00
Jens Reinemann
4c2f5f08a4 feat(app): User-Konzept App-Phase - JWT-Auth, Login, WebSocket-Client (#57)
- SettingsKeys: API_KEY entfernt, AUTH_ACCESS_TOKEN/REFRESH_TOKEN/USERNAME hinzugefügt
- SyncService: login() und logout() Interface-Methoden
- SyncServiceImpl: Bearer-Token statt X-API-Key, Auto-Refresh bei 401
- AuthModels: LoginRequest, LoginResponse, RefreshRequest
- WebSocketClient: Interface + Impl mit exponentiellem Backoff
- SettingsViewModel: Login/Logout, WebSocket-Connect, FullSyncRequired auto-pullSync
- SettingsScreen: Login-Formular (Username + Passwort) statt API-Key-Feld
- NetworkModule: WebSocketClient als Singleton gebunden
- Alle Tests gruen (70 Tasks up-to-date)
2026-05-16 19:45:11 +02:00
Jens Reinemann
14631c7327 feat(server): User-Konzept Auth, JWT, Admin-CRUD, WebSocket-Push, Admin-UI (#57)
- Users-Tabelle mit bcrypt-Passwort-Hash
- JWT-Auth (Access + Refresh Token) ersetzt API-Key
- POST /api/auth/login + /api/auth/refresh
- Admin-Endpoints: GET/POST/DELETE/PUT /api/admin/users
- Seed-Admin beim Start (KRISENVORRAT_ADMIN_PASSWORD)
- Inventar-Endpoints user-spezifisch (userId aus JWT)
- PATCH /api/inventory/items/{id} fuer Einzel-Updates
- WebSocket /ws/sync mit Push-Events (inventoryUpdated, fullSyncRequired)
- Minimale Admin-Web-UI unter /admin/ (XSS-sicher)
- Categories/Locations: Surrogate-PK fuer User-Isolation
- Alle Server-Tests gruen (43 Tests)
2026-05-16 19:28:03 +02:00
Jens Reinemann
db72a8b4ad ci: Android CI deaktivieren (nur noch manuell per workflow_dispatch) 2026-05-16 18:58:49 +02:00
Jens Reinemann
504207376f docs: SSH-Public-Key fuer VPS-Zugang hinterlegen 2026-05-16 18:56:07 +02:00
Jens Reinemann
748140acbd docs: VPS-Deploy Skill hinzufügen (1984 Hosting, Docker, SSH) 2026-05-16 18:47:50 +02:00
Jens Reinemann
809e6aa069 feat: FEATURE_CAMERA_ENABLED compile flag für KI-Kamera
- build.gradle.kts: buildConfigField FEATURE_CAMERA_ENABLED (default: true)
- ItemListScreen: Camera-Icon nur wenn Flag gesetzt, onCameraClick optional
- KrisenvorratNavGraph: CameraCapture-Route und Lambda nur wenn Flag gesetzt
- SettingsScreen: KI-Erkennung-Section nur wenn Flag gesetzt
2026-05-16 18:06:12 +02:00
Jens Reinemann
dd571f46fc feat: KI-Kameraerkennung via OpenAI Vision (Issue #48)
- CameraCapture-Screen: Foto aufnehmen, analysieren, Artikel auswählen
- OpenAiVisionService: gpt-4o Vision API via Ktor (buildJsonObject)
- CameraViewModel: @ApplicationContext, Bitmap-Laden, Nav-Event via UiState
- ItemFormViewModel: prefillJson-Route-Parameter, _pendingCategoryName-Matching
- Settings: OpenAI API-Key (OPENAI_API_KEY) speichern/laden
- Screen.CameraCapture + Screen.ItemForm(prefillJson) in NavGraph
- ItemListScreen: PhotoCamera-Icon in TopAppBar
- AndroidManifest: TakePicture braucht keine CAMERA-Permission (Intent-basiert)
- 8 neue CameraViewModel-Tests, 1 neuer ItemFormViewModel-Test (226 Tests grün)
2026-05-16 17:58:08 +02:00
Jens Reinemann
f4b5197b06 infra: DB-Migration-Infrastruktur einrichten (#49)
- fallbackToDestructiveMigration() entfernt (war inakzeptabel)
- addMigrations(MIGRATION_1_2) in DatabaseModule eingetragen
- Migrations.kt: Migration(1,2) mit Tabellen-Neubau fuer SQLite < 3.25
  (kcal_per_100g -> kcal_per_kg, min_stock entfernt)
- exportSchema = true + KSP-Argument room.schemaLocation = app/schemas/
- 2.json Schema-Snapshot eingecheckt (Basis fuer kuenftige Migrationen)
- androidTest-Assets zeigen auf app/schemas/ (fuer MigrationTestHelper)
- KrisenvorratDatabaseMigrationTest: 4 instrumentierte Tests
  - Datenerhalt nach Migration
  - Korrekte Spalten nach Migration
  - Indices nach Migration
  - Fresh-Install ohne Migration
2026-05-16 14:52:06 +02:00
Jens Reinemann
018d8dc7da feat: Monat/Jahr-Picker statt Tages-Datepicker fuer Ablaufdatum (#52)
- ExpiryDateField: DatePicker entfernt, neuer MonthYearPickerDialog
  mit zwei Dropdowns (Monat + Jahr)
- Gespeicherter Wert: letzter Tag des gewaehlten Monats (atEndOfMonth())
- Anzeigeformat: MM/yyyy statt dd.MM.yyyy (ItemFormScreen + ItemListScreen)
- TextField ganzflaechig klickbar (nicht nur Icon)
- Dialog: OK / Entfernen / Abbrechen
- remember fuer DateTimeFormatter und Listenliterale
- Test auf Monatsende-Datum ausgerichtet
2026-05-16 14:39:39 +02:00
Jens Reinemann
b7f27b6f81 feat(item): DatePicker durch Monat/Jahr-Picker ersetzen
- Ablaufdatum wird jetzt als MM/yyyy gespeichert (letzter Tag des Monats)
- DatePickerDialog -> AlertDialog mit zwei Dropdowns (Monat, Jahr)
- Anzeige in ItemListScreen ebenfalls auf MM/yyyy umgestellt
2026-05-16 14:37:54 +02:00
Jens Reinemann
fcc7142ea1 fix: Room DB-Version auf 2 erhöhen nach Schema-Änderung
kcalPerKg-Umbenennung und minStock-Entfernung haben den Identity-Hash
geändert. fallbackToDestructiveMigration() greift nur bei Version-
wechsel – daher version=1→2 notwendig.
2026-05-16 14:33:05 +02:00
Jens Reinemann
8280a9daf9 refactor: kcal/100g -> kcal/kg umbenennen und Mindestbestand entfernen
- ItemEntity, ItemDto: kcalPer100g -> kcalPerKg (kcal_per_kg),
  minStock-Spalte komplett entfernt
- CalculateSupplyRangeUseCase: Formel angepasst (/ 1000.0 * kcalPerKg)
- GetMinStockWarningsUseCase + MinStockWarning: gelöscht
- UI (ItemFormScreen, WarningsScreen, DashboardScreen): Mindestbestand-
  Felder und Warnungsabschnitte entfernt
- ViewModels, UiState, Repository: alle Referenzen bereinigt
- Server (Tables, InventoryRepository): Schema angepasst
- Room: fallbackToDestructiveMigration() hinzugefügt (keine Produktivdaten)
- Alle 434 Tests gruen
2026-05-16 14:19:10 +02:00
Jens Reinemann
395939a4ec feat(categories): Umbenennen, Löschen mit Umzuweisungs-Dialog, letzter Lagerort vorauswählen (#51)
- Kategorien und Lagerorte umbenennen (Edit-Dialog)
- Löschen mit Umzuweisungs-Dialog wenn Artikel referenzieren
- Letzten verwendeten Lagerort im Artikelformular vorausauswählen
- stale lastLocationId-Validierung gegen aktuelle Location-Liste
- !! durch ?.let ersetzt in beiden Screens
- Irreführenden Delete-Dialog-Text korrigiert
- Tests: 20 neue Unit-Tests (Rename, Reassign, dismissReassign, staleLocation)
2026-05-16 14:05:45 +02:00
Jens Reinemann
caf7002406 fix: Seed-Daten beim App-Start prüfen und ggf. einfügen
RoomDatabase.Callback.onCreate() wird bei adb install -r nicht erneut
ausgeführt, da die DB bereits existiert. Kategorien und Orte blieben
deshalb leer.

Lösung: SeedDatabaseUseCase prüft beim App-Start ob Kategorien/Orte
vorhanden sind und befüllt die Tabellen nur wenn sie leer sind.
2026-05-16 13:57:04 +02:00
Jens Reinemann
9cc15ffaad feat(settings): Kinder-Altersgruppen für Kalorienverbrauch (#47)
domain/model/AgeGroup.kt:
- Neues Enum AgeGroup (6 Gruppen: Kleinkind bis Erwachsener) mit Richtwert-kcal
- AgeGroupEntry-Datenklasse (count + kcalPerDay, anpassbar)
- JSON-Serialisierung via kotlinx.serialization
- Migrationspfad: householdSize + kcalPerPerson → ERWACHSENER-Gruppe

domain/model/SettingsKeys.kt:
- Neue Konstanten-Klasse für Settings-Keys (löst SettingsViewModel-Kopplung im DashboardViewModel auf)

CalculateSupplyRangeUseCase: Signatur auf totalDailyKcal vereinfacht
SettingsViewModel/UiState: ageGroups statt householdSize + dailyKcalPerPerson
DashboardViewModel: combine(3 flows), AGE_GROUPS statt 4 separate Flows
SettingsScreen: Altersgruppen-Tabelle statt zwei TextFields
ImportExportRepositoryImpl: Markdown-Export zeigt Altersgruppen-Gesamtkcal

Tests: +8 neue Tests (Migration, Validierung, Fallbacks), alle bestehenden Tests aktualisiert

Closes #47
2026-05-16 13:35:27 +02:00
Jens Reinemann
1236d61543 docs(device): Wireless ADB workflow und Screenshot-Pull dokumentiert
- Wireless ADB als bevorzugten Verbindungsweg dokumentiert
- Pull-Workflow für Screenshots (exec-out liefert über WLAN korrupte Bilder)
- Hinweis: adb -d nur USB, Wireless braucht adb -s <IP>:<PORT>
- Vollständiger Wireless-Deploy-Workflow (Build/Install/Launch)
2026-05-16 12:55:35 +02:00
Jens Reinemann
d97882cfd6 ci: add Android CI/CD workflow
.github/workflows/android-ci.yml:
- Triggers on push to main and pull requests
- Ubuntu-latest runner with Java 17 (Temurin)
- Gradle cache via gradle/actions/setup-gradle
- Jobs: assembleDebug build + unit tests (./gradlew test)
- Uploads debug APK as workflow artifact (14-day retention)

Closes #14
2026-05-14 21:48:16 +02:00
Jens Reinemann
cb576349e0 feat(server): add LAN dev-server integration & end-to-end sync tests
Start scripts (PS1 + Shell), Dockerfile, E2E sync tests, and README
documentation for Phase 2 LAN server deployment.

New files:
- start-server.ps1 / start-server.sh: one-command server startup with
  auto-build, LAN-IP detection, and configurable API key
- Dockerfile: multi-stage build (Gradle → JRE Alpine) for container
  deployment with volume mount for persistent data
- .dockerignore: excludes app/, .git, build artifacts from Docker context
- EndToEndSyncTest.kt: 7 E2E tests covering full push/pull sync cycle,
  multi-client overwrite, empty DB pull, multiple round-trips, and auth
  rejection for unauthenticated requests
- README.md: project overview, build instructions, and complete Phase 2
  server setup docs (4 start options, LAN setup, API reference, security)

Changed files:
- AndroidManifest.xml: added usesCleartextTraffic=true for HTTP in LAN

Closes #46
2026-05-14 21:45:33 +02:00
Jens Reinemann
a972ce34ca feat(settings): add sync UI with server configuration and push/pull actions
Closes #45

SettingsScreen:
- Server-URL and API-Key input fields (API-Key masked as password)
- Push (upload) and Pull (download) sync buttons
- Sync status indicator (running/success/error)
- Last sync timestamp display (persisted via Room settings)

SettingsViewModel:
- Inject SyncService for server communication
- pushSync(): exports local inventory to InventoryDto, uploads via SyncService
- pullSync(): downloads InventoryDto from server, imports into local DB
- Persists server_url, api_key, sync_last_timestamp in Room settings table

ImportExportRepository:
- New methods exportToInventoryDto() and importFromInventoryDto()
- Refactored to eliminate code duplication via buildInventoryDto() and
  applyInventoryDto() helper methods

Tests:
- 8 new ViewModel tests covering sync settings loading, push/pull success,
  push/pull error scenarios, and sync status dismissal
- FakeSyncService and extended FakeImportExportRepository for testing
2026-05-14 21:30:55 +02:00
Jens Reinemann
215790d68e feat(app): add Ktor HTTP client and SyncService for inventory sync
domain/model/SyncError.kt:
- Sealed class with ConnectionError, Timeout, AuthError, ServerError,
  NotConfigured, Unknown subtypes for typed error handling

domain/repository/SyncService.kt:
- Interface with downloadInventory() and uploadInventory() returning
  Result<InventoryDto> for clean error propagation

data/sync/SyncServiceImpl.kt:
- Ktor Client implementation using OkHttp engine
- GET /api/inventory and PUT /api/inventory endpoints
- X-API-Key header authentication matching server contract
- Server URL and API key read from SettingsRepository
- withContext(Dispatchers.IO) for network calls
- Catches SocketTimeoutException, ConnectException specifically

di/NetworkModule.kt:
- Hilt module providing singleton HttpClient with OkHttp engine
- ContentNegotiation with kotlinx.serialization JSON
- Configurable connect/read/write timeouts (10s/30s/30s)
- Binds SyncServiceImpl to SyncService interface

Dependencies:
- ktor-client-core, ktor-client-okhttp,
  ktor-client-content-negotiation, ktor-client-mock (test)
- ktor-serialization-kotlinx-json (shared with server)
- INTERNET permission added to AndroidManifest.xml

Tests: 9 tests with Ktor MockEngine covering success, 401, 500,
missing config, trailing slash URL normalization

Closes #44
2026-05-14 21:14:40 +02:00
Jens Reinemann
cb9bd2bdf4 feat(server): add API-Key authentication for REST endpoints
server/plugins/Authentication.kt:
- Custom Ktor AuthenticationProvider supporting both X-API-Key header
  and Authorization: Bearer <key> for API-Key validation
- ApiKeyPrincipal data class implementing Principal interface
- 401 Unauthorized with ErrorResponse body for missing/invalid keys

server/plugins/Routing.kt:
- Inventory routes wrapped in authenticate(api-key) block
- Health endpoint remains public (no auth required)

server/src/main/resources/application.conf:
- API key configurable via krisenvorrat.apiKey property
- Environment variable override via KRISENVORRAT_API_KEY

server/tests:
- 7 new AuthenticationTest cases (valid bearer, valid X-API-Key,
  missing key, invalid bearer, invalid X-API-Key, PUT without key,
  health without key)
- All existing ApplicationTest cases updated with bearer auth header

Closes #43
2026-05-14 20:50:16 +02:00
Jens Reinemann
5974144621 feat(server): add REST-API endpoints for inventory sync & CRUD
server/src/main/kotlin/.../routes/InventoryRoutes.kt:
- GET /api/inventory: returns full inventory as JSON
- PUT /api/inventory: full-sync replaces entire server inventory

server/src/main/kotlin/.../plugins/StatusPages.kt:
- Structured error handling via Ktor StatusPages plugin
- BadRequestException, SerializationException, IllegalArgumentException → 400
- Unhandled exceptions → 500 with logging

server/src/main/kotlin/.../plugins/CallLogging.kt:
- Request logging via Ktor CallLogging plugin (INFO level)

server/src/main/kotlin/.../model/ErrorResponse.kt:
- Serializable error response DTO (status + message)

server/src/main/kotlin/.../plugins/Routing.kt:
- Health endpoint moved from /health to /api/health
- Inventory routes mounted under /api/inventory

server/src/main/kotlin/.../Application.kt:
- Added configurePlugins() for testability (DB init separate)
- StatusPages and CallLogging plugins configured

server/src/test/.../ApplicationTest.kt:
- 8 endpoint tests using Ktor TestApplication with in-memory H2
- Tests: health, 404, empty GET, PUT valid, PUT+GET roundtrip,
  invalid JSON → 400, data replacement, JSON content type

Closes #42
2026-05-14 20:30:34 +02:00
Jens Reinemann
2387c6ee5a feat(server): add Exposed ORM database layer with H2
server/db/Tables.kt:
- Exposed table definitions for Categories, Locations, Items, Settings
- Schema mirrors Room entities from app module
- Foreign keys on Items referencing Categories and Locations

server/db/DatabaseFactory.kt:
- H2 file-based DB initialization (jdbc:h2:file:./data/krisenvorrat)
- Parameterized for testability (in-memory DB for tests)
- Schema auto-creation via SchemaUtils.create()

server/repository/InventoryRepository.kt:
- Full CRUD: saveInventory() and loadInventory()
- Atomic replace via transaction (deleteAll + insert)
- Direct mapping between Exposed rows and shared DTOs

4 repository tests with H2 in-memory covering:
- Empty DB, full round-trip, overwrite, nullable fields

Closes #41
2026-05-14 20:15:07 +02:00
Jens Reinemann
cb190e61e9 feat(server): add Ktor server module with health endpoint
New Gradle module :server (Kotlin/JVM) with Ktor 3.1.2 framework,
configured as an embedded Netty HTTP server.

server/src/main/kotlin/de/krisenvorrat/server/:
- Application.kt: entry point using EngineMain for HOCON config
- plugins/Routing.kt: GET /health endpoint returning 200 OK
- plugins/Serialization.kt: ContentNegotiation with kotlinx.json

Configuration:
- application.conf (HOCON): host 0.0.0.0, port 8080, module reference
- logback.xml: SLF4J/Logback console logging

Build config:
- server/build.gradle.kts: Ktor plugin with Fat JAR (server.jar)
- libs.versions.toml: Ktor 3.1.2, Logback 1.5.18 dependencies
- settings.gradle.kts: include(:server)
- :server depends on :shared for common DTO models

Tests: 2 tests (health endpoint, 404 on unknown route) via
Ktor testApplication.

Closes #40
2026-05-14 20:06:40 +02:00
Jens Reinemann
c0c4978ccf feat(shared): add shared module with common DTO models
New Gradle module :shared (pure Kotlin/JVM) containing @Serializable
DTO classes for use by both the Android app and future Ktor server.

shared/src/main/kotlin/de/krisenvorrat/shared/model/:
- InventoryDto: root DTO replacing ExportData (version, categories,
  locations, items, settings)
- CategoryDto, LocationDto, ItemDto, SettingDto: extracted from
  the former *Export data classes in :app

Migration in :app:
- ExportData.kt deleted (classes moved to :shared)
- ImportExportRepositoryImpl now imports from de.krisenvorrat.shared.model
- app/build.gradle.kts adds implementation(project(:shared))

Build config:
- libs.versions.toml: added kotlin-jvm plugin entry
- build.gradle.kts (root): registered kotlin-jvm plugin
- settings.gradle.kts: include(:shared)

JSON wire format is unchanged; all 165 existing tests pass.

Closes #39
2026-05-14 19:50:23 +02:00
Jens Reinemann
309587bc36 docs(server-tech): ADR für Server-Technologie – Ktor gewählt
Anforderungen/design/server-tech/adr-server-technology.md:
Architecture Decision Record für die Server-Technologie in Phase 2
(Geräte-Synchronisierung). Ktor gewählt wegen gleicher Sprache
(Kotlin), kotlinx.serialization-Kompatibilität, Code-Sharing-
Möglichkeit, geringem Ressourcenverbrauch und JetBrains-Support.

Geprüfte Alternativen: Spring Boot, Node.js+Express, Python+FastAPI.

Closes #10
2026-05-14 19:22:27 +02:00
Jens Reinemann
ce851af37b feat(settings): add JSON import with SAF file picker
SettingsScreen: Added import button that opens the system file picker
(ActivityResultContracts.OpenDocument) filtered to application/json.
After file selection, a confirmation dialog warns that existing data
will be overwritten. Import result is shown in a success/error dialog.

SettingsViewModel: Added onImportFileSelected(uri), onImportConfirmed(),
onImportDismissed(), onImportResultDismissed() methods. The import reads
the file via contentResolver.openInputStream() and delegates to the
existing ImportExportRepository.importFromJson(). Settings are reloaded
after successful import.

SettingsUiState: Extended with isImporting, importResult (sealed
interface ImportResult with Success/Error), and pendingImportUri for
the confirmation dialog flow.

SettingsViewModelTest: Added 6 unit tests covering import success,
invalid JSON error, empty file, null input stream, dialog state
management, and result dismissal.

Closes #38
2026-05-14 03:35:50 +02:00
Jens Reinemann
8193445939 feat(settings): add JSON/Markdown export via Share Intent
Implement export functionality in the Settings screen allowing users to
share their inventory data as JSON (via FileProvider + ACTION_SEND with
EXTRA_STREAM) or Markdown (via ACTION_SEND with EXTRA_TEXT).

Key changes:
- ShareContent sealed interface for export events (Json with URI,
  Markdown with text)
- SettingsViewModel: exportJson() writes to cache file and creates
  FileProvider URI; exportMarkdown() provides text directly
- SettingsUiState: isExporting, shareContent, exportError fields
- SettingsScreen: LaunchedEffect consumes share events and opens
  Android Share Sheet via Intent.createChooser
- FileProvider registered in AndroidManifest with cache-path config
- MockK added as test dependency for FileProvider static mocking
- 8 new unit tests covering export success, failure, and state cleanup

Closes #37
2026-05-14 03:26:15 +02:00
Jens Reinemann
12f787a406 feat(export): add exportToMarkdown() to ImportExportRepository
Implement Markdown export for the entire inventory (Issue #36).
The method renders categories as headings with items in a table
(Name, Menge, Einheit, MHD, Lagerort). Empty categories are skipped.
Dates are formatted as dd.MM.yyyy (German), quantities use German
decimal format (comma). Settings section shows household_size and
kcal_per_day if present.

Includes 6 unit tests covering: full export, empty categories,
missing expiry date, settings section, fractional quantities, and
irrelevant settings omission.

Closes #36
2026-05-14 03:04:43 +02:00
Jens Reinemann
e85b151cd5 feat(settings): implement SettingsScreen with ViewModel, UI and persistence
Implement the full Settings tab with household size and daily kcal/person
input fields, persisted via Room through the existing SettingsRepository.
The DashboardViewModel now reads settings reactively and passes them to
CalculateSupplyRangeUseCase instead of using hardcoded defaults.

Changes:
- Add observeValue(key) Flow method to SettingsDao and SettingsRepository
- Create SettingsViewModel with load/save logic and input validation
- Create SettingsUiState data class
- Replace SettingsScreen placeholder with full Compose UI
  (household size, kcal/day fields, save button, export/import placeholders)
- Integrate settings into DashboardViewModel via combine() with 4 flows
- Add SettingsViewModelTest (6 tests covering defaults, persistence, validation)
- Update DashboardViewModelTest and test fakes for new constructor parameter

Closes #35
2026-05-14 02:50:44 +02:00
Jens Reinemann
34bd1f603f feat(warnings): implement dedicated Warnings screen with ViewModel
ui/warnings/WarningsScreen.kt: full implementation replacing placeholder.
Shows expiry warnings (colored by urgency: URGENT=error, WARNING=orange)
and min-stock warnings as individual cards in a LazyColumn. Displays
empty state when no warnings exist.

ui/warnings/WarningsViewModel.kt: HiltViewModel observing ItemRepository
flow, delegates to GetExpiryWarningsUseCase and GetMinStockWarningsUseCase.
Exposes WarningsUiState via StateFlow.

ui/warnings/WarningsUiState.kt: data class with expiryWarnings,
minStockWarnings, isLoading, and derived properties (totalWarningCount,
hasWarnings).

ui/dashboard/DashboardScreen.kt: replaced ExpiryWarningsCard and
MinStockWarningsCard with compact WarningsSummaryCard showing only
warning counts. Removed unused domain model imports.

tests: 7 WarningsViewModel unit tests covering empty state, expiry
warnings, min-stock warnings, combined counts, reactive updates.

Closes #34
2026-05-14 02:39:46 +02:00
Jens Reinemann
a4c0dc63b4 feat(navigation): implement Bottom Navigation Bar with 4 tabs and app shell
MainScreen.kt: new app shell with Scaffold + Material 3 NavigationBar
providing 4 tabs (Uebersicht, Inventur, Warnungen, Einstellungen).

TopLevelDestination.kt: enum defining tab routes, icons (Home, Inventory2,
Warning, Settings), and labels for the navigation bar.

Screen.kt: added Warnings and Settings sealed interface members.

KrisenvorratNavGraph.kt: accepts Modifier, added Warnings/Settings
composables, removed obsolete DashboardScreen navigation callback.

DashboardScreen.kt: removed Scaffold wrapper and onNavigateToItems param,
now uses Column layout (TopAppBar handled inline).

ItemListScreen.kt: removed onDashboardClick param and Dashboard menu entry
(no longer needed with tab navigation).

WarningsScreen.kt, SettingsScreen.kt: placeholder screens for future impl.

MainActivity.kt: delegates to MainScreen instead of NavGraph directly.

Added material-icons-extended dependency for Inventory2 icon.

Closes #33
2026-05-14 02:25:47 +02:00
Jens Reinemann
c88d10be10 feat(theme): add Material 3 custom dark theme with seed #4A6741
Color.kt: New file with M3 color tokens generated from olive green
seed color #4A6741. Defines primary, secondary, tertiary, error,
surface, and container colors for the dark color scheme.

Theme.kt: Updated DarkColorScheme with all custom color tokens,
changed default to darkTheme=true, status bar now uses surface
color instead of primary for better edge-to-edge appearance.

themes.xml: Changed splash theme parent from Material.Light to
Material dark, added dark background/status/navigation bar colors
matching the Compose surface color (#1A1C18).

Closes #32
2026-05-14 02:05:05 +02:00