Files
CalTracker/backend/app/schemas.py
T

192 lines
3.5 KiB
Python

from datetime import date as date_type
from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
from app.models import MealType
class UserCreate(BaseModel):
username: str
password: str
class UserRead(BaseModel):
id: int
username: str
calorie_goal: float
protein_goal: float
carbs_goal: float
fat_goal: float
class UserSummary(BaseModel):
username: str
class GoalsUpdate(BaseModel):
calorie_goal: float
protein_goal: float
carbs_goal: float
fat_goal: float
class Token(BaseModel):
access_token: str
token_type: str = "bearer"
class TokenData(BaseModel):
username: str | None = None
class ProductBase(BaseModel):
barcode: str
name: str
calories: float
carbs: float
protein: float
fat: float
sugar: float = 0.0
fiber: float = 0.0
saturated_fat: float = 0.0
salt: float = 0.0
class ProductCreate(ProductBase):
barcode: str | None = None
class ProductRead(ProductBase):
pass
class ProductSearchResult(ProductRead):
last_amount_g: float | None = None
is_dish: bool = False
class NutritionEstimateRequest(BaseModel):
description: str = Field(min_length=2, max_length=300)
class NutritionEstimateResponse(BaseModel):
name: str
calories: float = Field(ge=0, le=900)
carbs: float = Field(ge=0, le=100)
protein: float = Field(ge=0, le=100)
fat: float = Field(ge=0, le=100)
sugar: float = Field(default=0.0, ge=0, le=100)
fiber: float = Field(default=0.0, ge=0, le=100)
saturated_fat: float = Field(default=0.0, ge=0, le=100)
salt: float = Field(default=0.0, ge=0, le=100)
portion_g: float = Field(ge=1, le=5000)
class LogCreate(BaseModel):
barcode: str | None = None
name: str | None = None
amount_g: float
meal_type: MealType
class LogUpdate(BaseModel):
amount_g: float | None = None
meal_type: MealType | None = None
class LogRead(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: int
barcode: str | None
name: str
meal_type: MealType
amount_g: float
calories: float
carbs: float
protein: float
fat: float
sugar: float
fiber: float
saturated_fat: float
salt: float
timestamp: datetime
class DailyTotals(BaseModel):
calories: float
carbs: float
protein: float
fat: float
sugar: float
fiber: float
saturated_fat: float
salt: float
class DailyLogResponse(BaseModel):
logs: list[LogRead]
totals: DailyTotals
class DailyHistoryEntry(BaseModel):
date: date_type
totals: DailyTotals
class HistoryResponse(BaseModel):
days: list[DailyHistoryEntry]
class DishIngredientInput(BaseModel):
barcode: str
amount_g: float
class DishIngredientRead(BaseModel):
barcode: str
name: str
amount_g: float
calories: float
carbs: float
protein: float
fat: float
sugar: float
fiber: float
saturated_fat: float
salt: float
class DishCreate(BaseModel):
name: str
instructions: str | None = None
ingredients: list[DishIngredientInput]
class DishRead(BaseModel):
id: int
name: str
instructions: str | None
barcode: str
total_weight_g: float
calories: float
carbs: float
protein: float
fat: float
sugar: float
fiber: float
saturated_fat: float
salt: float
ingredients: list[DishIngredientRead]
is_owner: bool
owner_username: str
class DishShareCreate(BaseModel):
username: str
class DishShareRead(BaseModel):
username: str