mirror of
https://github.com/escalante29/healthy-fit.git
synced 2026-03-21 12:28:46 +01:00
Initial project scaffolding for health tracker app
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.
This commit is contained in:
54
backend/app/api/v1/endpoints/nutrition.py
Normal file
54
backend/app/api/v1/endpoints/nutrition.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from typing import Any
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from sqlmodel import Session
|
||||
from app.api import deps
|
||||
from app.ai.nutrition import nutrition_module, NutritionalInfo
|
||||
from app.core.security import create_access_token # Just ensuring we have auth imports if needed later
|
||||
from app.models.user import User
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class AnalyzeRequest(BaseModel):
|
||||
description: str
|
||||
|
||||
from app.models.food import FoodLog, FoodItem
|
||||
from app.api.deps import get_session
|
||||
from app.core.security import get_password_hash # Not needed
|
||||
from app.config import settings
|
||||
|
||||
@router.post("/analyze", response_model=NutritionalInfo)
|
||||
def analyze_food(
|
||||
request: AnalyzeRequest,
|
||||
) -> Any:
|
||||
"""
|
||||
Analyze food description and return nutritional info using DSPy.
|
||||
"""
|
||||
try:
|
||||
result = nutrition_module(description=request.description)
|
||||
return result.nutritional_info
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@router.post("/log", response_model=FoodLog)
|
||||
def log_food(
|
||||
*,
|
||||
session: Session = Depends(deps.get_session),
|
||||
nutrition_info: NutritionalInfo,
|
||||
current_user: deps.CurrentUser,
|
||||
) -> Any:
|
||||
"""
|
||||
Save food log to database.
|
||||
"""
|
||||
food_log = FoodLog(
|
||||
user_id=current_user.id,
|
||||
name=nutrition_info.name,
|
||||
calories=nutrition_info.calories,
|
||||
protein=nutrition_info.protein,
|
||||
carbs=nutrition_info.carbs,
|
||||
fats=nutrition_info.fats,
|
||||
)
|
||||
session.add(food_log)
|
||||
session.commit()
|
||||
session.refresh(food_log)
|
||||
return food_log
|
||||
Reference in New Issue
Block a user