This commit is contained in:
2025-09-09 06:04:29 -07:00
parent a62b4e8c12
commit 2cc2b4c9ce
33 changed files with 6066 additions and 322 deletions

View File

@@ -0,0 +1,23 @@
from fastapi import APIRouter, Depends, BackgroundTasks
from sqlalchemy.ext.asyncio import AsyncSession
from app.dependencies import verify_api_key
from app.services.workout_sync import WorkoutSyncService
from app.database import get_db
router = APIRouter(dependencies=[Depends(verify_api_key)])
@router.post("/sync")
async def trigger_garmin_sync(
background_tasks: BackgroundTasks,
db: AsyncSession = Depends(get_db)
):
"""Trigger background sync of Garmin activities"""
sync_service = WorkoutSyncService(db)
background_tasks.add_task(sync_service.sync_recent_activities, days_back=14)
return {"message": "Garmin sync started"}
@router.get("/sync-status")
async def get_sync_status(db: AsyncSession = Depends(get_db)):
"""Get latest sync status"""
sync_service = WorkoutSyncService(db)
return await sync_service.get_latest_sync_status()

View File

@@ -32,6 +32,21 @@ async def read_workout(workout_id: int, db: AsyncSession = Depends(get_db)):
raise HTTPException(status_code=404, detail="Workout not found")
return workout
@router.get("/{workout_id}/metrics", response_model=list[schemas.WorkoutMetric])
async def get_workout_metrics(
workout_id: int,
db: AsyncSession = Depends(get_db)
):
"""Get time-series metrics for a workout"""
workout = await db.get(Workout, workout_id)
if not workout:
raise HTTPException(status_code=404, detail="Workout not found")
if not workout.metrics:
return []
return workout.metrics
@router.post("/sync")
async def trigger_garmin_sync(
@@ -135,4 +150,17 @@ async def approve_analysis(
return {"message": "Analysis approved", "new_plan_id": new_plan.id if new_plan else None}
await db.commit()
return {"message": "Analysis approved"}
return {"message": "Analysis approved"}
@router.get("/plans/{plan_id}/evolution", response_model=List[schemas.Plan])
async def get_plan_evolution(
plan_id: int,
db: AsyncSession = Depends(get_db)
):
"""Get full evolution history for a plan."""
evolution_service = PlanEvolutionService(db)
plans = await evolution_service.get_plan_evolution_history(plan_id)
if not plans:
raise HTTPException(status_code=404, detail="Plan not found")
return plans