This repository has been archived on 2026-02-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
breakpilot-pwa/backend/notification_api.py
BreakPilot Dev 19855efacc
Some checks failed
Tests / Go Tests (push) Has been cancelled
Tests / Python Tests (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / Go Lint (push) Has been cancelled
Tests / Python Lint (push) Has been cancelled
Tests / Security Scan (push) Has been cancelled
Tests / All Checks Passed (push) Has been cancelled
Security Scanning / Secret Scanning (push) Has been cancelled
Security Scanning / Dependency Vulnerability Scan (push) Has been cancelled
Security Scanning / Go Security Scan (push) Has been cancelled
Security Scanning / Python Security Scan (push) Has been cancelled
Security Scanning / Node.js Security Scan (push) Has been cancelled
Security Scanning / Docker Image Security (push) Has been cancelled
Security Scanning / Security Summary (push) Has been cancelled
CI/CD Pipeline / Go Tests (push) Has been cancelled
CI/CD Pipeline / Python Tests (push) Has been cancelled
CI/CD Pipeline / Website Tests (push) Has been cancelled
CI/CD Pipeline / Linting (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Docker Build & Push (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / CI Summary (push) Has been cancelled
ci/woodpecker/manual/build-ci-image Pipeline was successful
ci/woodpecker/manual/main Pipeline failed
feat: BreakPilot PWA - Full codebase (clean push without large binaries)
All services: admin-v2, studio-v2, website, ai-compliance-sdk,
consent-service, klausur-service, voice-service, and infrastructure.
Large PDFs and compiled binaries excluded via .gitignore.
2026-02-11 13:25:58 +01:00

143 lines
3.7 KiB
Python

"""
Notification API - Proxy zu Go Consent Service für Benachrichtigungen
"""
from fastapi import APIRouter, HTTPException, Header, Query
from typing import Optional
import httpx
router = APIRouter(prefix="/v1/notifications", tags=["Notifications"])
CONSENT_SERVICE_URL = "http://localhost:8081"
async def proxy_request(
method: str,
path: str,
authorization: Optional[str] = None,
json_data: dict = None,
params: dict = None
):
"""Proxy request to Go consent service."""
headers = {}
if authorization:
headers["Authorization"] = authorization
async with httpx.AsyncClient() as client:
try:
response = await client.request(
method,
f"{CONSENT_SERVICE_URL}{path}",
headers=headers,
json=json_data,
params=params,
timeout=30.0
)
if response.status_code >= 400:
raise HTTPException(
status_code=response.status_code,
detail=response.json().get("error", "Request failed")
)
return response.json()
except httpx.RequestError as e:
raise HTTPException(status_code=503, detail=f"Consent service unavailable: {str(e)}")
@router.get("")
async def get_notifications(
limit: int = Query(20, ge=1, le=100),
offset: int = Query(0, ge=0),
unread_only: bool = Query(False),
authorization: Optional[str] = Header(None)
):
"""Holt alle Benachrichtigungen des aktuellen Benutzers."""
params = {
"limit": limit,
"offset": offset,
"unread_only": str(unread_only).lower()
}
return await proxy_request(
"GET",
"/api/v1/notifications",
authorization=authorization,
params=params
)
@router.get("/unread-count")
async def get_unread_count(
authorization: Optional[str] = Header(None)
):
"""Gibt die Anzahl ungelesener Benachrichtigungen zurück."""
return await proxy_request(
"GET",
"/api/v1/notifications/unread-count",
authorization=authorization
)
@router.put("/{notification_id}/read")
async def mark_as_read(
notification_id: str,
authorization: Optional[str] = Header(None)
):
"""Markiert eine Benachrichtigung als gelesen."""
return await proxy_request(
"PUT",
f"/api/v1/notifications/{notification_id}/read",
authorization=authorization
)
@router.put("/read-all")
async def mark_all_as_read(
authorization: Optional[str] = Header(None)
):
"""Markiert alle Benachrichtigungen als gelesen."""
return await proxy_request(
"PUT",
"/api/v1/notifications/read-all",
authorization=authorization
)
@router.delete("/{notification_id}")
async def delete_notification(
notification_id: str,
authorization: Optional[str] = Header(None)
):
"""Löscht eine Benachrichtigung."""
return await proxy_request(
"DELETE",
f"/api/v1/notifications/{notification_id}",
authorization=authorization
)
@router.get("/preferences")
async def get_preferences(
authorization: Optional[str] = Header(None)
):
"""Holt die Benachrichtigungseinstellungen des Benutzers."""
return await proxy_request(
"GET",
"/api/v1/notifications/preferences",
authorization=authorization
)
@router.put("/preferences")
async def update_preferences(
preferences: dict,
authorization: Optional[str] = Header(None)
):
"""Aktualisiert die Benachrichtigungseinstellungen."""
return await proxy_request(
"PUT",
"/api/v1/notifications/preferences",
authorization=authorization,
json_data=preferences
)