a79ab37add
- Rinomina _RecipeSummary -> RecipeSummary: il leading underscore
segnalava "privato" ma la classe e usata come response_model pubblico
ed esposta nell'OpenAPI schema.
- Aggiunge commento esplicativo sopra /by-code/{code}/recipes sul perche
l'ordine di dichiarazione conta (protezione gia data dal tipo int di
station_id, ma esplicito per prevenire regressioni durante refactor).
- Detail message del 404 by-code uniformato a "Station not found"
(senza distinguere not-found vs inactive, evita leak di esistenza).
- Aggiunge 3 test mancanti sul router:
* test_admin_can_list_stations (copertura happy path + active_only)
* test_assign_recipe_not_found_returns_404
* test_duplicate_assignment_returns_409
Feedback da code-reviewer su Task 5. Full suite: 11/11 passed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
"""Pydantic schemas for Station and StationRecipeAssignment."""
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
|
|
class StationCreate(BaseModel):
|
|
code: str = Field(..., min_length=1, max_length=100)
|
|
name: str = Field(..., min_length=1, max_length=255)
|
|
location: Optional[str] = Field(default=None, max_length=255)
|
|
notes: Optional[str] = None
|
|
active: bool = True
|
|
|
|
|
|
class StationUpdate(BaseModel):
|
|
name: Optional[str] = Field(default=None, min_length=1, max_length=255)
|
|
location: Optional[str] = Field(default=None, max_length=255)
|
|
notes: Optional[str] = None
|
|
active: Optional[bool] = None
|
|
|
|
|
|
class StationResponse(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
id: int
|
|
code: str
|
|
name: str
|
|
location: Optional[str]
|
|
notes: Optional[str]
|
|
active: bool
|
|
created_by: int
|
|
created_at: datetime
|
|
|
|
|
|
class StationRecipeAssignmentCreate(BaseModel):
|
|
recipe_id: int = Field(..., gt=0)
|
|
|
|
|
|
class StationRecipeAssignmentResponse(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
id: int
|
|
station_id: int
|
|
recipe_id: int
|
|
assigned_by: int
|
|
assigned_at: datetime
|
|
|
|
|
|
class RecipeSummary(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
id: int
|
|
code: str
|
|
name: str
|
|
active: bool
|
|
|
|
|
|
class StationWithRecipesResponse(StationResponse):
|
|
recipes: list[RecipeSummary] = Field(default_factory=list)
|