33 lines
750 B
Python
33 lines
750 B
Python
from typing import Optional
|
|
|
|
from pydantic import BaseModel, EmailStr, Field
|
|
|
|
|
|
# Base User Schema
|
|
class UserBase(BaseModel):
|
|
email: EmailStr
|
|
username: str
|
|
is_active: Optional[bool] = True
|
|
is_superuser: Optional[bool] = False
|
|
|
|
|
|
# Schema for creating a new user
|
|
class UserCreate(UserBase):
|
|
password: str = Field(..., min_length=8)
|
|
|
|
|
|
# Schema for updating an existing user
|
|
class UserUpdate(BaseModel):
|
|
email: Optional[EmailStr] = None
|
|
username: Optional[str] = None
|
|
password: Optional[str] = Field(None, min_length=8)
|
|
is_active: Optional[bool] = None
|
|
is_superuser: Optional[bool] = None
|
|
|
|
|
|
# Schema for returning user data
|
|
class UserResponse(UserBase):
|
|
id: int
|
|
|
|
class Config:
|
|
from_attributes = True |