d6508e0ae8
Implementazione completa del backend FastAPI: - Modelli SQLAlchemy: User, Recipe, RecipeVersion, RecipeTask, RecipeSubtask, Measurement, AccessLog, SystemSetting, RecipeVersionAudit - Schemas Pydantic v2 per tutti i CRUD + statistiche SPC - Middleware: API Key auth (X-API-Key) con role checking + access logging - Router: auth, users, recipes, tasks, measurements, files, settings - Services: auth (bcrypt+secrets), recipe (copy-on-write versioning), measurement (auto pass/fail con UTL/UWL/LWL/LTL) - Alembic env.py con import modelli attivi - Fix architect review: no double-commit, recipe_id subquery filter, user_id in access logs, type annotations corrette Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
"""Pydantic schemas for Recipe and RecipeVersion operations."""
|
|
from datetime import datetime
|
|
from typing import Optional, TYPE_CHECKING
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
if TYPE_CHECKING:
|
|
from schemas.task import TaskResponse
|
|
|
|
|
|
class RecipeCreate(BaseModel):
|
|
"""Schema for creating a new recipe."""
|
|
code: str = Field(..., min_length=1, max_length=100)
|
|
name: str = Field(..., min_length=1, max_length=255)
|
|
description: Optional[str] = None
|
|
|
|
|
|
class RecipeUpdate(BaseModel):
|
|
"""Schema for updating a recipe (creates new version)."""
|
|
name: Optional[str] = Field(None, min_length=1, max_length=255)
|
|
description: Optional[str] = None
|
|
change_notes: Optional[str] = None
|
|
|
|
|
|
class RecipeVersionResponse(BaseModel):
|
|
"""Schema for recipe version response."""
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
recipe_id: int
|
|
version_number: int
|
|
is_current: bool
|
|
created_by: int
|
|
created_at: datetime
|
|
change_notes: Optional[str] = None
|
|
tasks: list["TaskResponse"] = []
|
|
|
|
|
|
class RecipeResponse(BaseModel):
|
|
"""Schema for recipe response."""
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
code: str
|
|
name: str
|
|
description: Optional[str] = None
|
|
created_by: int
|
|
created_at: datetime
|
|
active: bool
|
|
current_version: Optional[RecipeVersionResponse] = None
|
|
|
|
|
|
class RecipeListResponse(BaseModel):
|
|
"""Schema for paginated recipe list."""
|
|
items: list[RecipeResponse]
|
|
total: int
|
|
page: int
|
|
per_page: int
|
|
pages: int
|
|
|
|
|
|
# Forward reference imports for model_rebuild
|
|
from schemas.task import TaskResponse # noqa: E402
|
|
RecipeVersionResponse.model_rebuild()
|
|
RecipeResponse.model_rebuild()
|