Add User schema
This commit is contained in:
parent
d7c46b7bde
commit
0ae69d98f6
@ -1,34 +1,61 @@
|
||||
from pydantic import BaseModel, Field, EmailStr
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
|
||||
class UserRoles(str, Enum):
|
||||
admin = "admin"
|
||||
user = "user"
|
||||
|
||||
class UserBase(BaseModel):
|
||||
username: str = Field(..., min_length=3, max_length=50)
|
||||
email: EmailStr = Field(...)
|
||||
full_name: str = Field(..., min_length=1, max_length=100)
|
||||
username: str = Field(..., min_length=1, max_length=50)
|
||||
email: EmailStr = Field(..., max_length=255)
|
||||
first_name: str = Field(..., max_length=50)
|
||||
last_name: str = Field(..., max_length=50)
|
||||
phone_number: str = Field(..., max_length=20)
|
||||
role: UserRoles
|
||||
is_active: bool = True
|
||||
is_verified: bool = False
|
||||
|
||||
class UserCreate(UserBase):
|
||||
password: str = Field(..., min_length=8, max_length=100)
|
||||
password: str = Field(..., min_length=8, max_length=255)
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"username": "johndoe",
|
||||
"email": "john@example.com",
|
||||
"full_name": "John Doe",
|
||||
"password": "securepass123"
|
||||
"password": "securepass123",
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"phone_number": "+1234567890",
|
||||
"role": "user",
|
||||
"is_active": True,
|
||||
"is_verified": False
|
||||
}
|
||||
}
|
||||
|
||||
class UserResponse(UserBase):
|
||||
is_active: bool = True
|
||||
id: int
|
||||
last_login: Optional[datetime]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"id": 1,
|
||||
"username": "johndoe",
|
||||
"email": "john@example.com",
|
||||
"full_name": "John Doe",
|
||||
"is_active": True
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"phone_number": "+1234567890",
|
||||
"role": "user",
|
||||
"is_active": True,
|
||||
"is_verified": False,
|
||||
"last_login": "2023-01-01T00:00:00",
|
||||
"created_at": "2023-01-01T00:00:00",
|
||||
"updated_at": "2023-01-01T00:00:00"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user