mirror of
https://github.com/sstent/AICyclingCoach.git
synced 2026-03-18 02:46:03 +00:00
sync
This commit is contained in:
23
backend/app/routes/garmin.py
Normal file
23
backend/app/routes/garmin.py
Normal 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()
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user