llm-api/plan_session_router.py aktualisiert
All checks were successful
Deploy Trainer_LLM to llm-node / deploy (push) Successful in 1s

This commit is contained in:
Lars 2025-08-12 16:26:15 +02:00
parent 36c82ac942
commit ff58caaad0

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
"""
plan_session_router.py v0.1.0 (WP-15)
plan_session_router.py v0.2.0 (WP-15)
CRUD-Minimum für Plan-Sessions (POST/GET).
CRUD-Minimum für Plan-Sessions (POST/GET) mit Referenz-Validierung.
Kompatibel zum Qdrant-Client-Stil der bestehenden Router.
"""
from fastapi import APIRouter, HTTPException
@ -21,6 +21,7 @@ router = APIRouter(tags=["plan_sessions"])
# Konfiguration
# -----------------
PLAN_SESSION_COLLECTION = os.getenv("PLAN_SESSION_COLLECTION", "plan_sessions")
PLAN_COLLECTION = os.getenv("PLAN_COLLECTION", "plans")
# -----------------
# Modelle
@ -86,6 +87,10 @@ def _get_by_field(collection: str, key: str, value: Any) -> Optional[Dict[str, A
@router.post("/plan_sessions", response_model=PlanSession)
def create_plan_session(s: PlanSession):
_ensure_collection(PLAN_SESSION_COLLECTION)
# Referenz auf Plan prüfen
if not _get_by_field(PLAN_COLLECTION, "id", s.plan_id):
raise HTTPException(status_code=422, detail=f"Unknown plan_id: {s.plan_id}")
# Normalisieren
s.used_equipment = _norm_list(s.used_equipment)
payload = s.model_dump()