mirror of
https://github.com/escalante29/healthy-fit.git
synced 2026-03-21 09:08:46 +01:00
Set up backend and frontend structure for a health and fitness tracker using Python (FastAPI, SQLModel, DSPy) and React. Includes Docker and Compose configs, authentication, nutrition AI module, health/nutrition/user endpoints, database models, and basic frontend with routing and context. Enables tracking nutrition, health metrics, and user management, with architecture ready for future mobile and cloud deployment.
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from typing import Any, List
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlmodel import Session, select
|
|
from app.api import deps
|
|
from app.models.health import HealthMetric
|
|
from pydantic import BaseModel
|
|
|
|
router = APIRouter()
|
|
|
|
class HealthMetricCreate(BaseModel):
|
|
metric_type: str
|
|
value: float
|
|
unit: str
|
|
user_id: int # TODO: remove when auth is fully integrated
|
|
|
|
@router.post("/", response_model=HealthMetric)
|
|
def create_metric(
|
|
*,
|
|
session: Session = Depends(deps.get_session),
|
|
metric_in: HealthMetricCreate,
|
|
) -> Any:
|
|
metric = HealthMetric(metric_type=metric_in.metric_type, value=metric_in.value, unit=metric_in.unit, user_id=metric_in.user_id)
|
|
session.add(metric)
|
|
session.commit()
|
|
session.refresh(metric)
|
|
return metric
|
|
|
|
@router.get("/{user_id}", response_model=List[HealthMetric])
|
|
def read_metrics(
|
|
user_id: int,
|
|
session: Session = Depends(deps.get_session),
|
|
) -> Any:
|
|
statement = select(HealthMetric).where(HealthMetric.user_id == user_id)
|
|
metrics = session.exec(statement).all()
|
|
return metrics
|