Add User schema
This commit is contained in:
parent
5841fe78cc
commit
b022540d3f
54
schemas/user.py
Normal file
54
schemas/user.py
Normal file
@ -0,0 +1,54 @@
|
||||
from pydantic import BaseModel, Field, EmailStr
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
class UserBase(BaseModel):
|
||||
username: str = Field(..., min_length=3, max_length=50)
|
||||
email: EmailStr = Field(...)
|
||||
company_name: Optional[str] = None
|
||||
role: str = Field(default="user")
|
||||
phone: Optional[str] = None
|
||||
address: Optional[str] = None
|
||||
is_active: bool = True
|
||||
account_balance: float = 0.0
|
||||
|
||||
class UserCreate(UserBase):
|
||||
password: str = Field(..., min_length=8)
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"username": "johndoe",
|
||||
"email": "john@example.com",
|
||||
"password": "securepass123",
|
||||
"company_name": "Acme Corp",
|
||||
"role": "user",
|
||||
"phone": "+1234567890",
|
||||
"address": "123 Main St",
|
||||
"is_active": True,
|
||||
"account_balance": 0.0
|
||||
}
|
||||
}
|
||||
|
||||
class UserResponse(UserBase):
|
||||
id: int
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"id": 1,
|
||||
"username": "johndoe",
|
||||
"email": "john@example.com",
|
||||
"company_name": "Acme Corp",
|
||||
"role": "user",
|
||||
"phone": "+1234567890",
|
||||
"address": "123 Main St",
|
||||
"is_active": True,
|
||||
"account_balance": 0.0,
|
||||
"created_at": "2023-01-01T00:00:00",
|
||||
"updated_at": "2023-01-01T00:00:00"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user