mirror of
https://github.com/escalante29/healthy-fit.git
synced 2026-03-21 09:08:46 +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.
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from datetime import timedelta
|
|
from typing import Any
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from fastapi.security import OAuth2PasswordRequestForm
|
|
from sqlmodel import Session, select
|
|
|
|
from app.api import deps
|
|
from app.config import settings
|
|
from app.core import security
|
|
from app.models.user import User
|
|
from app.schemas.token import Token
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/login/access-token", response_model=Token)
|
|
def login_access_token(
|
|
session: Session = Depends(deps.get_session), form_data: OAuth2PasswordRequestForm = Depends()
|
|
) -> Any:
|
|
"""
|
|
OAuth2 compatible token login, get an access token for future requests
|
|
"""
|
|
statement = select(User).where(User.email == form_data.username)
|
|
user = session.exec(statement).first()
|
|
|
|
if not user or not security.verify_password(form_data.password, user.password_hash):
|
|
raise HTTPException(status_code=400, detail="Incorrect email or password")
|
|
|
|
access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
|
return {
|
|
"access_token": security.create_access_token(user.id, expires_delta=access_token_expires),
|
|
"token_type": "bearer",
|
|
}
|