mirror of
https://github.com/escalante29/healthy-fit.git
synced 2026-03-21 19:48:47 +01:00
Introduces DSPy-based nutrition and plan generation modules, including image analysis for nutritional info and personalized diet/exercise plans. Adds new API endpoints for health metrics/goals, nutrition image analysis, and plan management. Updates models, schemas, and backend structure to support these features, and includes initial training data and configuration for prompt optimization.
81 lines
2.0 KiB
Python
81 lines
2.0 KiB
Python
from datetime import datetime
|
|
from typing import Any, List
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel
|
|
from sqlmodel import Session, select
|
|
|
|
from app.api import deps
|
|
from app.models.health import HealthGoal, HealthMetric
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class HealthMetricCreate(BaseModel):
|
|
metric_type: str
|
|
value: float
|
|
unit: str
|
|
|
|
|
|
class HealthGoalCreate(BaseModel):
|
|
goal_type: str
|
|
target_value: float
|
|
target_date: datetime | None = None
|
|
|
|
|
|
@router.post("/metrics", response_model=HealthMetric)
|
|
def create_metric(
|
|
*,
|
|
session: Session = Depends(deps.get_session),
|
|
current_user: deps.CurrentUser,
|
|
metric_in: HealthMetricCreate,
|
|
) -> Any:
|
|
metric = HealthMetric(
|
|
metric_type=metric_in.metric_type, value=metric_in.value, unit=metric_in.unit, user_id=current_user.id
|
|
)
|
|
session.add(metric)
|
|
session.commit()
|
|
session.refresh(metric)
|
|
return metric
|
|
|
|
|
|
@router.get("/metrics", response_model=List[HealthMetric])
|
|
def read_metrics(
|
|
current_user: deps.CurrentUser,
|
|
session: Session = Depends(deps.get_session),
|
|
) -> Any:
|
|
statement = (
|
|
select(HealthMetric).where(HealthMetric.user_id == current_user.id).order_by(HealthMetric.timestamp.desc())
|
|
)
|
|
metrics = session.exec(statement).all()
|
|
return metrics
|
|
|
|
|
|
@router.post("/goals", response_model=HealthGoal)
|
|
def create_goal(
|
|
*,
|
|
session: Session = Depends(deps.get_session),
|
|
current_user: deps.CurrentUser,
|
|
goal_in: HealthGoalCreate,
|
|
) -> Any:
|
|
goal = HealthGoal(
|
|
goal_type=goal_in.goal_type,
|
|
target_value=goal_in.target_value,
|
|
target_date=goal_in.target_date,
|
|
user_id=current_user.id,
|
|
)
|
|
session.add(goal)
|
|
session.commit()
|
|
session.refresh(goal)
|
|
return goal
|
|
|
|
|
|
@router.get("/goals", response_model=List[HealthGoal])
|
|
def read_goals(
|
|
current_user: deps.CurrentUser,
|
|
session: Session = Depends(deps.get_session),
|
|
) -> Any:
|
|
statement = select(HealthGoal).where(HealthGoal.user_id == current_user.id)
|
|
goals = session.exec(statement).all()
|
|
return goals
|