shinkan-jinkendo/backend/routers/planning_exercise_suggest.py
Lars 0b203489f7
All checks were successful
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 41s
Test Suite / playwright-tests (push) Successful in 1m21s
Implement Graph Visibility Promotion Logic and Update UI Components
- Added a new function `_graph_promotion_transition` to determine the necessary exercise visibility changes during graph promotions.
- Updated the `list_visibility_promotion_candidates` endpoint to utilize the new promotion logic, ensuring accurate exercise visibility handling.
- Enhanced the frontend components to prompt users for exercise visibility adjustments based on graph visibility changes, improving user experience.
- Introduced tests for the new promotion logic to ensure correctness and reliability in visibility transitions.
2026-06-14 07:30:26 +02:00

114 lines
4.1 KiB
Python

"""
POST /api/planning/exercise-suggest — planungsgebundene Übungssuche (Hybrid + Profil + optional LLM-Rerank).
"""
from fastapi import APIRouter, Depends
from db import get_db, get_cursor
from tenant_context import TenantContext, get_tenant_context
from planning_exercise_suggest import PlanningExerciseSuggestRequest, suggest_planning_exercises
from planning_exercise_path_builder import ProgressionPathSuggestRequest, suggest_progression_path
from account_lifecycle import assert_min_account_state
from capabilities import probe_capability
from club_features import (
consume_club_feature_with_usage,
merge_feature_usage_into_response,
probe_club_feature_access,
resolve_club_id_for_probe,
)
router = APIRouter(prefix="/api/planning", tags=["planning_exercise_suggest"])
@router.post("/exercise-suggest")
def post_planning_exercise_suggest(
body: PlanningExerciseSuggestRequest,
tenant: TenantContext = Depends(get_tenant_context),
):
uses_ai = body.include_llm_intent or body.include_llm_rank
club_id = resolve_club_id_for_probe(tenant) if uses_ai else None
if uses_ai:
assert_min_account_state(tenant, "active_member", endpoint="POST /planning/exercise-suggest")
probe_capability(
tenant,
"planning.ai.suggest",
action="planning_suggest",
club_id=club_id,
endpoint="POST /planning/exercise-suggest",
)
probe_club_feature_access(
feature_id="ai_calls",
action="planning_suggest",
club_id=club_id,
profile_id=tenant.profile_id,
portal_role=tenant.global_role,
endpoint="POST /planning/exercise-suggest",
tenant=tenant,
)
with get_db() as conn:
cur = get_cursor(conn)
result = suggest_planning_exercises(cur, tenant=tenant, body=body)
if uses_ai:
usage = consume_club_feature_with_usage(
feature_id="ai_calls",
club_id=club_id,
profile_id=tenant.profile_id,
portal_role=tenant.global_role,
action="planning_suggest",
cur=cur,
tenant=tenant,
conn=conn,
)
result = merge_feature_usage_into_response(result, usage)
return result
@router.post("/progression-path-suggest")
def post_progression_path_suggest(
body: ProgressionPathSuggestRequest,
tenant: TenantContext = Depends(get_tenant_context),
):
uses_ai = (
body.include_llm_intent
or body.include_llm_path_qa
or body.include_llm_roadmap
or body.include_llm_start_target
or (body.start_target_only and body.include_llm_start_target)
)
club_id = resolve_club_id_for_probe(tenant) if uses_ai else None
if uses_ai:
assert_min_account_state(
tenant, "active_member", endpoint="POST /planning/progression-path-suggest"
)
probe_capability(
tenant,
"planning.ai.progression_path",
action="progression_path_suggest",
club_id=club_id,
endpoint="POST /planning/progression-path-suggest",
)
probe_club_feature_access(
feature_id="ai_calls",
action="progression_path_suggest",
club_id=club_id,
profile_id=tenant.profile_id,
portal_role=tenant.global_role,
endpoint="POST /planning/progression-path-suggest",
tenant=tenant,
)
with get_db() as conn:
cur = get_cursor(conn)
result = suggest_progression_path(cur, tenant=tenant, body=body)
if uses_ai:
usage = consume_club_feature_with_usage(
feature_id="ai_calls",
club_id=club_id,
profile_id=tenant.profile_id,
portal_role=tenant.global_role,
action="progression_path_suggest",
cur=cur,
tenant=tenant,
conn=conn,
)
result = merge_feature_usage_into_response(result, usage)
return result