Add User schema
This commit is contained in:
parent
3b9dae6e38
commit
e333bf9b2d
50
schemas/user.py
Normal file
50
schemas/user.py
Normal file
@ -0,0 +1,50 @@
|
||||
from pydantic import BaseModel, Field, EmailStr
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
class UserBase(BaseModel):
|
||||
username: str = Field(..., min_length=3, max_length=50)
|
||||
email: EmailStr = Field(..., description="Email address")
|
||||
first_name: Optional[str] = Field(None, max_length=50)
|
||||
last_name: Optional[str] = Field(None, max_length=50)
|
||||
phone: Optional[str] = Field(None, regex="^\+?1?\d{9,15}$")
|
||||
|
||||
class UserCreate(UserBase):
|
||||
password: str = Field(..., min_length=8, max_length=100)
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"username": "johndoe",
|
||||
"email": "john@example.com",
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"phone": "+1234567890",
|
||||
"password": "securepass123"
|
||||
}
|
||||
}
|
||||
|
||||
class User(UserBase):
|
||||
id: UUID
|
||||
is_active: bool = True
|
||||
is_verified: bool = False
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"id": "550e8400-e29b-41d4-a716-446655440000",
|
||||
"username": "johndoe",
|
||||
"email": "john@example.com",
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"phone": "+1234567890",
|
||||
"is_active": True,
|
||||
"is_verified": False,
|
||||
"created_at": "2023-01-01T00:00:00",
|
||||
"updated_at": "2023-01-01T00:00:00"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user