2025-03-28 04:36:07 +00:00

52 lines
1.6 KiB
Python

from pydantic import BaseModel, Field, EmailStr
from typing import Optional
class UserBase(BaseModel):
first_name: str = Field(..., min_length=2, max_length=50)
last_name: str = Field(..., min_length=2, max_length=50)
email: EmailStr = Field(..., description="User email address")
phone: str = Field(..., min_length=10, max_length=15)
address: Optional[str] = Field(None, max_length=200)
city: Optional[str] = Field(None, max_length=100)
country: Optional[str] = Field(None, max_length=100)
is_active: bool = True
is_admin: bool = False
class UserCreate(UserBase):
password: str = Field(..., min_length=8, max_length=100)
class Config:
schema_extra = {
"example": {
"first_name": "John",
"last_name": "Doe",
"email": "john.doe@example.com",
"phone": "1234567890",
"password": "securepass123",
"address": "123 Main St",
"city": "New York",
"country": "USA",
"is_active": True,
"is_admin": False
}
}
class UserResponse(UserBase):
id: int
class Config:
orm_mode = True
schema_extra = {
"example": {
"id": 1,
"first_name": "John",
"last_name": "Doe",
"email": "john.doe@example.com",
"phone": "1234567890",
"address": "123 Main St",
"city": "New York",
"country": "USA",
"is_active": True,
"is_admin": False
}
}