diff --git a/.env.example b/.env.example index a2089a7..ba8a48a 100644 --- a/.env.example +++ b/.env.example @@ -16,3 +16,6 @@ LOG_LEVEL=INFO # Optional: Healthchecks.io / Uptime Kuma URL (wird nach jedem Sync gepingt) # HEALTHCHECK_URL=https://hc-ping.com/DEINE_UUID + +# API Server +API_PORT=8000 diff --git a/Dockerfile b/Dockerfile index 988c193..a77286b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY sync.py . +COPY api/ ./api/ ENV PYTHONUNBUFFERED=1 diff --git a/PLAN.md b/PLAN.md new file mode 100644 index 0000000..510c817 --- /dev/null +++ b/PLAN.md @@ -0,0 +1,133 @@ +# PLAN.md - Implementierungsplan + +Feature: REST API + Web-Frontend für Calendar Sync + +## Übersicht + +Ziel: FastAPI-basierte API und ein Jinja2 Web-Frontend hinzufügen, um die nächsten 10 Termine aus MariaDB auszulesen und anzuzeigen. Gleicher Docker Build, separater Container. + +--- + +## Phase 1: Projektstruktur + Shared Module + +### Step 1.1: API-Verzeichnisstruktur anlegen +``` +api/ +├── __init__.py +├── main.py +├── database.py +└── templates/ + └── index.html +``` + +### Step 1.2: database.py - DB Connection extrahieren +- `get_connection()` Funktion aus `sync.py:81-89` in `api/database.py` verschieben +- Connection Pooling optional (First: einfacher single connection) +- Umgebungsvariablen identisch zu sync.py +- sync.py importiert dann `from api.database import get_connection` + +**Dateien:** `api/__init__.py`, `api/database.py`, `sync.py` (Import anpassen) + +--- + +## Phase 2: FastAPI Backend + +### Step 2.1: api/main.py - FastAPI App erstellen +- FastAPI Instanz erstellen +- GET `/api/events` Endpoint + - Query Parameter: `limit` (default 10, max 50), `calendar_label` (optional), `search` (optional) + - SQL bei search: `WHERE deleted=0 AND start_at >= NOW() AND summary LIKE %s ORDER BY start_at ASC LIMIT %s` + - SQL ohne search: `WHERE deleted=0 AND start_at >= NOW() ORDER BY start_at ASC LIMIT %s` + - Response als JSON +- GET `/api/events/{id}` Endpoint + - Einzelnes Event nach ID +- GET `/api/health` Endpoint + - Response: `{"status": "ok"}` +- GET `/` Endpoint + - Jinja2 Template rendern mit Events + - Query Parameter `search` weiterleiten + +### Step 2.2: Response Model definieren +- Pydantic Model für Event Response +- DATETIME → String Konvertierung (ISO Format) + +**Dateien:** `api/main.py` + +--- + +## Phase 3: Web-Frontend + +### Step 3.1: api/templates/index.html +- Einfaches HTML5 Template +- Jinja2 Variablen: `{{ events }}`, `{{ search }}` +- CSS inline oder im ` + +
+