Automated Action 26ee3102eb Update to support Pydantic v2 syntax
- Fixed circular imports in schema files by moving imports to module level
- Changed orm_mode=True to model_config with from_attributes=True
- Updated validator decorators to field_validator in all schema files
- Properly annotated fields in all schema files for Pydantic v2 compatibility
2025-05-26 17:52:52 +00:00

64 lines
1.4 KiB
Python

from typing import List, Optional
from pydantic import BaseModel, EmailStr, Field, field_validator
# Import at module level to avoid circular imports
from app.schemas.client import Client
# Shared properties
class UserBase(BaseModel):
email: EmailStr
full_name: str
company_name: Optional[str] = None
address: Optional[str] = None
phone: Optional[str] = None
is_active: bool = True
# Properties to receive via API on creation
class UserCreate(UserBase):
password: str = Field(..., min_length=8)
@field_validator("password")
def password_validation(cls, v):
if len(v) < 8:
raise ValueError("Password must be at least 8 characters long")
return v
# Properties to receive via API on update
class UserUpdate(UserBase):
email: Optional[EmailStr] = None
full_name: Optional[str] = None
password: Optional[str] = None
@field_validator("password")
def password_validation(cls, v):
if v is not None and len(v) < 8:
raise ValueError("Password must be at least 8 characters long")
return v
# Properties shared by models stored in DB
class UserInDBBase(UserBase):
id: int
model_config = {
"from_attributes": True
}
# Properties to return via API
class User(UserInDBBase):
pass
# Properties stored in DB
class UserInDB(UserInDBBase):
hashed_password: str
# User with clients
class UserWithClients(User):
clients: List[Client] = []