42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
from pydantic import BaseModel, Field, EmailStr
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
class UserBase(BaseModel):
|
|
username: str = Field(..., min_length=1, max_length=50)
|
|
email: EmailStr = Field(..., max_length=100)
|
|
first_name: str = Field(..., max_length=50)
|
|
last_name: str = Field(..., max_length=50)
|
|
|
|
class UserCreate(UserBase):
|
|
password: str = Field(..., min_length=8, max_length=255)
|
|
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"username": "johndoe",
|
|
"email": "john@example.com",
|
|
"password": "securepass123",
|
|
"first_name": "John",
|
|
"last_name": "Doe"
|
|
}
|
|
}
|
|
|
|
class UserResponse(UserBase):
|
|
is_active: bool = True
|
|
is_verified: bool = False
|
|
last_login: Optional[datetime] = None
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"username": "johndoe",
|
|
"email": "john@example.com",
|
|
"first_name": "John",
|
|
"last_name": "Doe",
|
|
"is_active": True,
|
|
"is_verified": False,
|
|
"last_login": "2023-01-01T00:00:00"
|
|
}
|
|
} |