|
|
@@ -4,7 +4,7 @@ import httpx
|
|
|
import bcrypt
|
|
|
from contextlib import asynccontextmanager
|
|
|
from fastapi import FastAPI, HTTPException, Depends, Header
|
|
|
-from database import create_tables, create_user, get_user_by_username, create_session, get_user_from_token, delete_session, search_foods_by_name, save_chat_message, get_user_chat_history
|
|
|
+from database import create_tables, create_user, get_user_by_username, create_session, get_user_from_token, delete_session, search_foods_by_name, save_chat_message, get_user_chat_history, get_user_profile
|
|
|
from fastapi.responses import HTMLResponse, StreamingResponse
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
from pydantic import BaseModel
|
|
|
@@ -173,6 +173,27 @@ async def logout(authorization: Optional[str] = Header(None)):
|
|
|
delete_session(token)
|
|
|
return {"message": "Logged out successfully"}
|
|
|
|
|
|
+@app.get("/api/macros/targets")
|
|
|
+async def get_macro_targets(current_user: dict = Depends(get_current_user)):
|
|
|
+ """API endpoint to securely fetch the user's current macronutrient targets"""
|
|
|
+ profile = get_user_profile(current_user['id'])
|
|
|
+
|
|
|
+ if not profile:
|
|
|
+ # Fallback to defaults in case database insertion failed
|
|
|
+ return {
|
|
|
+ "calories": 2000,
|
|
|
+ "protein_g": 150,
|
|
|
+ "carbs_g": 200,
|
|
|
+ "fat_g": 65
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ "calories": profile.get("target_calories", 2000),
|
|
|
+ "protein_g": profile.get("target_protein_g", 150),
|
|
|
+ "carbs_g": profile.get("target_carbs_g", 200),
|
|
|
+ "fat_g": profile.get("target_fat_g", 65)
|
|
|
+ }
|
|
|
+
|
|
|
@app.post("/chat")
|
|
|
async def chat_endpoint(request: ChatRequest, current_user: dict = Depends(get_current_user)):
|
|
|
"""Proxy chat requests to the local Ollama instance with streaming support.
|