
- 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
36 lines
796 B
Python
36 lines
796 B
Python
from datetime import datetime
|
|
from typing import Optional
|
|
from pydantic import BaseModel
|
|
|
|
# Shared properties
|
|
class PostBase(BaseModel):
|
|
title: Optional[str] = None
|
|
content: Optional[str] = None
|
|
is_published: Optional[bool] = True
|
|
|
|
# Properties to receive on post creation
|
|
class PostCreate(PostBase):
|
|
title: str
|
|
content: str
|
|
|
|
# Properties to receive on post update
|
|
class PostUpdate(PostBase):
|
|
pass
|
|
|
|
# Properties shared by models stored in DB
|
|
class PostInDBBase(PostBase):
|
|
id: str
|
|
author_id: str
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
# Properties to return to client
|
|
class Post(PostInDBBase):
|
|
pass
|
|
|
|
# Properties stored in DB but not returned to the API client
|
|
class PostInDB(PostInDBBase):
|
|
pass |