
- Create project structure with app organization - Set up FastAPI application with CORS and health endpoint - Implement database models with SQLAlchemy (User, Post, Comment) - Set up Alembic for database migrations - Implement authentication with JWT tokens - Create CRUD operations for all models - Implement REST API endpoints for users, posts, and comments - Add comprehensive documentation in README.md
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
from pydantic import BaseModel, EmailStr
|
|
|
|
# Shared properties
|
|
class UserBase(BaseModel):
|
|
email: Optional[EmailStr] = None
|
|
username: Optional[str] = None
|
|
is_active: Optional[bool] = True
|
|
is_superuser: bool = False
|
|
full_name: Optional[str] = None
|
|
|
|
# Properties to receive on user creation
|
|
class UserCreate(UserBase):
|
|
email: EmailStr
|
|
username: str
|
|
password: str
|
|
|
|
# Properties to receive on user update
|
|
class UserUpdate(UserBase):
|
|
password: Optional[str] = None
|
|
|
|
# Properties shared by models stored in DB
|
|
class UserInDBBase(UserBase):
|
|
id: str
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
# Properties to return to client
|
|
class User(UserInDBBase):
|
|
pass
|
|
|
|
# Properties stored in DB but not returned to the client
|
|
class UserInDB(UserInDBBase):
|
|
hashed_password: str
|
|
|
|
# Token schema
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str
|
|
|
|
# Token payload
|
|
class TokenPayload(BaseModel):
|
|
sub: Optional[str] = None |