5cc576cec9
- Recipe model: add image_path field for recipe-level image
- RecipeSubtask model: add image_path for per-subtask detail images
- Schemas: add image_path to create/update/response for recipe and subtask
- Task router: pass image_path when creating tasks and subtasks
- Recipe service: copy image_path in versioning and update-in-place
- Users router: add PUT /{user_id}/password endpoint (admin only)
- User schema: add UserPasswordChange model
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
"""Pydantic schemas for User operations."""
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
|
|
class UserCreate(BaseModel):
|
|
"""Schema for creating a new user."""
|
|
username: str = Field(..., min_length=3, max_length=100)
|
|
password: str = Field(..., min_length=6, max_length=128)
|
|
email: Optional[str] = Field(None, max_length=255)
|
|
display_name: str = Field(..., min_length=1, max_length=255)
|
|
roles: list[str] = Field(default_factory=list)
|
|
is_admin: bool = False
|
|
language_pref: str = Field("it", pattern="^(it|en)$")
|
|
theme_pref: str = Field("light", pattern="^(light|dark)$")
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
"""Schema for updating a user (admin)."""
|
|
email: Optional[str] = Field(None, max_length=255)
|
|
display_name: Optional[str] = Field(None, min_length=1, max_length=255)
|
|
roles: Optional[list[str]] = None
|
|
is_admin: Optional[bool] = None
|
|
active: Optional[bool] = None
|
|
language_pref: Optional[str] = Field(None, pattern="^(it|en)$")
|
|
theme_pref: Optional[str] = Field(None, pattern="^(light|dark)$")
|
|
|
|
|
|
class UserProfileUpdate(BaseModel):
|
|
"""Schema for user self-update (profile)."""
|
|
display_name: Optional[str] = Field(None, min_length=1, max_length=255)
|
|
language_pref: Optional[str] = Field(None, pattern="^(it|en)$")
|
|
theme_pref: Optional[str] = Field(None, pattern="^(light|dark)$")
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
"""Schema for user response."""
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
username: str
|
|
email: Optional[str] = None
|
|
display_name: str
|
|
roles: list[str]
|
|
is_admin: bool
|
|
language_pref: str
|
|
theme_pref: str
|
|
active: bool
|
|
created_at: datetime
|
|
last_login: Optional[datetime] = None
|
|
|
|
|
|
class UserPasswordChange(BaseModel):
|
|
"""Schema for changing user password (admin only)."""
|
|
password: str = Field(..., min_length=6, max_length=128)
|
|
|
|
|
|
class LoginRequest(BaseModel):
|
|
"""Schema for login request."""
|
|
username: str
|
|
password: str
|
|
|
|
|
|
class LoginResponse(BaseModel):
|
|
"""Schema for login response."""
|
|
user: UserResponse
|
|
api_key: str
|
|
message: str = "Login successful"
|