perf-gen / app /api /endpoints /plans.py
pjxcharya's picture
Upload 16 files
426f314 verified
# app/api/endpoints/plans.py
from fastapi import APIRouter, HTTPException
# Import the new RestartPlanBody model
from app.core.models import GeneratePlanRequest, RevisePlanRequest, PlanResponse, RestartPlanBody
from app.services.planner_service import planner_service
router = APIRouter()
# Updated endpoint to pass the new attribute
@router.post("/generate", response_model=PlanResponse)
async def generate_new_plan(request: GeneratePlanRequest):
"""
Generates a new training plan based on athlete's profile and goal timeframe.
"""
plan_object = await planner_service.create_plan(
profile=request.athlete_profile,
plan_type=request.plan_type,
focus=request.focus,
time_to_achieve=request.time_to_achieve # Pass the new value
)
if "error" in plan_object:
raise HTTPException(status_code=500, detail=plan_object["error"])
return plan_object
# The revise endpoint remains unchanged
@router.post("/revise", response_model=PlanResponse)
async def revise_existing_plan(request: RevisePlanRequest):
"""
Revises an existing training plan based on feedback.
"""
revised_plan_object = await planner_service.update_plan(
original_plan=request.original_plan,
review=request.review
)
if "error" in revised_plan_object:
raise HTTPException(status_code=500, detail=revised_plan_object["error"])
return revised_plan_object
# vvv THIS IS THE NEW ENDPOINT vvv
@router.post("/athlete/{athlete_id}/restart", response_model=PlanResponse, tags=["Training Plans"])
async def restart_athlete_plan(athlete_id: str, request: RestartPlanBody):
"""
Archives the athlete's current plan and generates a new one.
This provides a 'Fresh Start' for the athlete.
"""
new_plan_object = await planner_service.restart_plan(
athlete_id=athlete_id,
new_plan_details=request.model_dump()
)
if "error" in new_plan_object:
raise HTTPException(status_code=500, detail=new_plan_object["error"])
return new_plan_object