Files
BSN-Livesystem/docs/alicia-aufgaben-phase3.md
T

125 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Alicia — Aufgaben 1620: BSN-Livesystem Phase 3 (Live-Vorbereitung)
> **Repo:** `git@git.datenhimmel.work:danielkrause/BSN-Livesystem.git`
> **Stand:** 15 Aufgaben fertig. Phase 2 abgeschlossen.
> **Ziel:** Projekt live-fähig machen — Config, DB, Error-Handling, Service-Dateien.
---
## Aufgabe 16 — Konfigurations-Management (pydantic-settings)
Ersetze hartcodierte Werte durch eine zentrale Config-Klasse.
### Datei 1: `src/config.py`
```python
from __future__ import annotations
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
"""Zentrale Anwendungskonfiguration. Werte aus .env oder Environment."""
REDIS_HOST: str = "localhost"
REDIS_PORT: int = 6379
WHATSAPP_APP_SECRET: str = ""
WHATSAPP_VERIFY_TOKEN: str = "bsn_verify_token"
TELEGRAM_BOT_TOKEN: str = ""
APP_HOST: str = "0.0.0.0"
APP_PORT: int = 5002
APP_DEBUG: bool = False
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
settings = Settings()
```
### Datei 2: `.env.template`
```
REDIS_HOST=localhost
REDIS_PORT=6379
WHATSAPP_APP_SECRET=dein_secret_hier
WHATSAPP_VERIFY_TOKEN=bsn_verify_token
TELEGRAM_BOT_TOKEN=dein_bot_token_hier
APP_DEBUG=false
```
### Integration: `src/app.py` umbauen
`from src.config import settings` — ersetze alle Hart-Konfigurationen.
### Test: `tests/test_config.py` — 4 Tests
**Commit:** `feat: Pydantic-Settings Konfiguration mit .env-Support`
---
## Aufgabe 17 — Einheitliche Fehlerbehandlung
Zentrale JSON-Error-Responses via Flask errorhandler.
### Datei: `src/error_handler.py`
Handler für 400, 401, 404, 422 (ValidationError), 500.
Alle Responses im Format: `{"error": "...", "message": "...", "status": N}`
### Integration: `register_error_handlers(app)` in `create_app()`
### Test: `tests/test_error_handler.py` — 5 Tests
**Commit:** `feat: Einheitliche JSON-Error-Responses`
---
## Aufgabe 18 — systemd Service-Dateien
### Dateien:
- `deploy/bsn-chatbot.service` — Flask-App als systemd-Service
- `deploy/bsn-worker.service` — Queue-Worker als systemd-Service
- `deploy/README.md` — Installationsanleitung
### Kein Test nötig (Konfigurationsdateien)
**Commit:** `feat: systemd-Service-Dateien für Chatbot + Queue-Worker`
---
## Aufgabe 19 — Health-Check erweitern
### Datei: `src/routes/health.py`
Blueprint mit:
- `GET /health` — Status, queue_size, python_version, platform
- `GET /health/ready` — Readiness-Check (Redis-Verbindung)
### Integration: `app.py`: inline `/health` entfernen, `health_bp` registrieren
### Test: `tests/test_health.py` — 4 Tests
**Commit:** `feat: Erweiterter Health-Check mit Readiness-Endpunkt`
---
## Aufgabe 20 — SQLAlchemy-Persistenz
### Dateien:
- `src/database.py` — Engine, Session, Base
- `src/models/spiel.py` — SpielDB (SQLAlchemy-Modell)
- `src/services/game_service.py` — Umbau auf DB-Sessions
### Test: `tests/test_database.py` — 5 Tests
**Commit:** `feat: SQLAlchemy-Datenbank mit SQLite-Persistenz`
---
## ⚠️ Wichtig
- `pip install pydantic-settings sqlalchemy`
- **Qualität:** `ruff check . && ruff format . && mypy --config-file pyproject.toml . && pytest -v`
- **Reihenfolge:** 16 → 17 → 18 → 19 → 20