72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
"""食谱相关 Pydantic 模型"""
|
|
|
|
from pydantic import BaseModel, Field
|
|
from typing import Optional, Dict, Any
|
|
from datetime import datetime
|
|
|
|
|
|
class RecipeCreate(BaseModel):
|
|
"""创建食谱请求"""
|
|
name: str = Field(..., min_length=1, max_length=200, description="菜名")
|
|
description: Optional[str] = Field(None, description="描述")
|
|
image_url: Optional[str] = Field(None, description="图片URL")
|
|
category: Optional[str] = Field(None, description="菜品分类")
|
|
cuisine: Optional[str] = Field(None, description="菜系")
|
|
user_notes: Optional[str] = Field(None, description="用户备注")
|
|
|
|
|
|
class RecipeUpdate(BaseModel):
|
|
"""更新食谱请求"""
|
|
name: Optional[str] = Field(None, min_length=1, max_length=200)
|
|
description: Optional[str] = None
|
|
image_url: Optional[str] = None
|
|
category: Optional[str] = None
|
|
cuisine: Optional[str] = None
|
|
status: Optional[str] = Field(None, pattern="^(draft|published|archived)$")
|
|
user_notes: Optional[str] = None
|
|
is_favorite: Optional[bool] = None
|
|
|
|
|
|
class RecipeResponse(BaseModel):
|
|
"""食谱响应"""
|
|
id: int
|
|
name: str
|
|
description: Optional[str]
|
|
image_url: Optional[str]
|
|
# 营养信息
|
|
calories: Optional[float]
|
|
protein: Optional[float]
|
|
fat: Optional[float]
|
|
carbs: Optional[float]
|
|
fiber: Optional[float]
|
|
# AI 识别相关
|
|
ai_recognition_confidence: Optional[float]
|
|
ai_analysis_result: Optional[Dict[str, Any]]
|
|
# 分类
|
|
category: Optional[str]
|
|
cuisine: Optional[str]
|
|
# 状态
|
|
status: str
|
|
# 用户标注
|
|
user_notes: Optional[str]
|
|
is_favorite: bool
|
|
# 时间戳
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class RecipeImageUploadRequest(BaseModel):
|
|
"""图片上传请求"""
|
|
image_base64: str = Field(..., description="Base64 编码的图片数据")
|
|
filename: Optional[str] = Field(None, description="原始文件名")
|
|
|
|
|
|
class RecipeAnalyzeCaloriesResponse(BaseModel):
|
|
"""热量分析响应"""
|
|
success: bool
|
|
data: Optional[RecipeResponse] = None
|
|
message: Optional[str] = None
|