52 lines
1.5 KiB
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, EmailStr, Field
class UserBase(BaseModel):
"""Base User schema with common attributes"""
email: EmailStr = Field(..., description="User email address")
username: str = Field(..., min_length=3, max_length=50, description="User username")
class UserCreate(UserBase):
"""Schema for creating a new user"""
password: str = Field(..., min_length=8, description="User password")
class UserUpdate(BaseModel):
"""Schema for updating an existing user, all fields are optional"""
email: Optional[EmailStr] = Field(None, description="User email address")
username: Optional[str] = Field(
None, min_length=3, max_length=50, description="User username",
)
password: Optional[str] = Field(None, min_length=8, description="User password")
is_active: Optional[bool] = Field(None, description="User active status")
is_superuser: Optional[bool] = Field(None, description="User superuser status")
class UserResponse(UserBase):
"""Schema for user response that includes database fields"""
id: int
is_active: bool
is_superuser: bool
created_at: datetime
updated_at: Optional[datetime] = None
class Config:
"""ORM mode config for the UserResponse schema"""
orm_mode = True
from_attributes = True
class Token(BaseModel):
"""Schema for JWT token"""
access_token: str
token_type: str
class TokenData(BaseModel):
"""Schema for JWT token data"""
username: Optional[str] = None