mirror of
https://github.com/escalante29/healthy-fit.git
synced 2026-03-21 14:08:48 +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.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
from typing import Annotated, Generator
|
|
|
|
from fastapi import Depends, HTTPException, status
|
|
from fastapi.security import OAuth2PasswordBearer
|
|
from jose import JWTError, jwt
|
|
from pydantic import ValidationError
|
|
from sqlmodel import Session
|
|
|
|
from app.config import settings
|
|
from app.core import security
|
|
from app.db import engine
|
|
from app.models.user import User
|
|
from app.schemas.token import TokenPayload
|
|
|
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/v1/login/access-token")
|
|
|
|
|
|
def get_session() -> Generator[Session, None, None]:
|
|
with Session(engine) as session:
|
|
yield session
|
|
|
|
|
|
SessionDep = Annotated[Session, Depends(get_session)]
|
|
TokenDep = Annotated[str, Depends(oauth2_scheme)]
|
|
|
|
|
|
def get_current_user(session: SessionDep, token: TokenDep) -> User:
|
|
try:
|
|
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=[security.ALGORITHM])
|
|
token_data = TokenPayload(**payload)
|
|
except (JWTError, ValidationError):
|
|
raise HTTPException(
|
|
status_code=status.HTTP_403_FORBIDDEN,
|
|
detail="Could not validate credentials",
|
|
)
|
|
user = session.get(User, int(token_data.sub))
|
|
if not user:
|
|
raise HTTPException(status_code=404, detail="User not found")
|
|
return user
|
|
|
|
|
|
CurrentUser = Annotated[User, Depends(get_current_user)]
|