
- Set up project structure with FastAPI - Configure SQLAlchemy with SQLite - Implement user and item models - Set up Alembic for database migrations - Create CRUD operations for models - Implement API endpoints for users and items - Add authentication functionality - Add health check endpoint - Configure Ruff for linting - Update README with comprehensive documentation
42 lines
967 B
Python
42 lines
967 B
Python
from typing import Optional
|
|
|
|
from pydantic import BaseModel, ConfigDict, EmailStr, Field
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
"""Base schema for User."""
|
|
email: EmailStr
|
|
username: str
|
|
is_active: bool = True
|
|
is_superuser: bool = False
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
"""Schema for creating a new User."""
|
|
password: str = Field(..., min_length=8)
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
"""Schema for updating a User."""
|
|
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
|
|
|
|
|
|
class UserInDBBase(UserBase):
|
|
"""Base schema for User in DB."""
|
|
id: int
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class User(UserInDBBase):
|
|
"""Schema for User returned to the client."""
|
|
pass
|
|
|
|
|
|
class UserInDB(UserInDBBase):
|
|
"""Schema for User in DB with password hash."""
|
|
hashed_password: str |