Add User schema
This commit is contained in:
parent
7017e53950
commit
1deabd46b2
43
schemas/user.py
Normal file
43
schemas/user.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
from pydantic import BaseModel, Field, EmailStr
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
class UserBase(BaseModel):
|
||||||
|
username: str = Field(..., min_length=3, max_length=50)
|
||||||
|
email: EmailStr = Field(...)
|
||||||
|
first_name: Optional[str] = Field(None, min_length=1, max_length=50)
|
||||||
|
last_name: Optional[str] = Field(None, min_length=1, max_length=50)
|
||||||
|
is_active: bool = True
|
||||||
|
is_superuser: bool = False
|
||||||
|
|
||||||
|
class UserCreate(UserBase):
|
||||||
|
password: str = Field(..., min_length=8, max_length=100)
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"username": "johndoe",
|
||||||
|
"email": "john@example.com",
|
||||||
|
"password": "secretpass123",
|
||||||
|
"first_name": "John",
|
||||||
|
"last_name": "Doe",
|
||||||
|
"is_active": True,
|
||||||
|
"is_superuser": False
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UserResponse(UserBase):
|
||||||
|
id: int = Field(...)
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"id": 1,
|
||||||
|
"username": "johndoe",
|
||||||
|
"email": "john@example.com",
|
||||||
|
"first_name": "John",
|
||||||
|
"last_name": "Doe",
|
||||||
|
"is_active": True,
|
||||||
|
"is_superuser": False
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user