Sprint 18: Notification Center, Routen entdecken, Onboarding, Admin-Erweiterungen

- Notifications: History-Tabelle, /api/notifications Endpoints, push.py schreibt in DB
- Notifications: Page (notifications.js) mit Badge, Typen-Icons, gelesen-Markierung
- Routen: Entdecken-Modus mit Ersteller-Anzeige, Nearby-Filter, Mine/Discover Toggle
- Onboarding: Willkommens-Modal nach Registrierung, Push-Angebot nach Login
- Admin: Scheduler-Tab (Jobs anzeigen + manuell triggern), System-Health (DB/Disk/Uptime)
- Admin: Audit-Log (wer hat was wann gemacht), erweiterte Stats (Push-Abos, aktive User, Routen)
- SW: by-v152, APP_VER 125
This commit is contained in:
rene 2026-04-17 23:21:48 +02:00
parent 5927d384bf
commit 92620c2c52
14 changed files with 1035 additions and 46 deletions

View file

@ -0,0 +1,90 @@
"""BAN YARO — Notification Center Routes"""
import logging
from fastapi import APIRouter, Depends, HTTPException
from database import db
from auth import get_current_user
router = APIRouter()
logger = logging.getLogger(__name__)
# ------------------------------------------------------------------
# GET /api/notifications — letzte 50 Benachrichtigungen des Users
# ------------------------------------------------------------------
@router.get("")
async def list_notifications(user=Depends(get_current_user)):
with db() as conn:
rows = conn.execute(
"""SELECT id, type, title, body, data, read_at, created_at
FROM notifications
WHERE user_id = ?
ORDER BY created_at DESC
LIMIT 50""",
(user["id"],),
).fetchall()
return [dict(r) for r in rows]
# ------------------------------------------------------------------
# GET /api/notifications/unread-count — Anzahl ungelesener Einträge
# ------------------------------------------------------------------
@router.get("/unread-count")
async def unread_count(user=Depends(get_current_user)):
with db() as conn:
row = conn.execute(
"SELECT COUNT(*) FROM notifications WHERE user_id=? AND read_at IS NULL",
(user["id"],),
).fetchone()
return {"count": row[0]}
# ------------------------------------------------------------------
# PATCH /api/notifications/read-all — alle als gelesen markieren
# ------------------------------------------------------------------
@router.patch("/read-all")
async def read_all(user=Depends(get_current_user)):
with db() as conn:
conn.execute(
"""UPDATE notifications
SET read_at = datetime('now')
WHERE user_id = ? AND read_at IS NULL""",
(user["id"],),
)
return {"ok": True}
# ------------------------------------------------------------------
# PATCH /api/notifications/{id}/read — einzelne als gelesen markieren
# ------------------------------------------------------------------
@router.patch("/{notif_id}/read")
async def read_one(notif_id: int, user=Depends(get_current_user)):
with db() as conn:
row = conn.execute(
"SELECT id FROM notifications WHERE id=? AND user_id=?",
(notif_id, user["id"]),
).fetchone()
if not row:
raise HTTPException(404, "Benachrichtigung nicht gefunden.")
conn.execute(
"UPDATE notifications SET read_at = datetime('now') WHERE id=?",
(notif_id,),
)
return {"ok": True}
# ------------------------------------------------------------------
# DELETE /api/notifications/{id} — löschen
# ------------------------------------------------------------------
@router.delete("/{notif_id}")
async def delete_one(notif_id: int, user=Depends(get_current_user)):
with db() as conn:
row = conn.execute(
"SELECT id FROM notifications WHERE id=? AND user_id=?",
(notif_id, user["id"]),
).fetchone()
if not row:
raise HTTPException(404, "Benachrichtigung nicht gefunden.")
conn.execute("DELETE FROM notifications WHERE id=?", (notif_id,))
return {"ok": True}