TASK-001: Setup FastAPI project structure
- Fixed main.py to include all route routers (posts, users, comments, feed) - Renamed app/models.py to app/schemas.py and split into proper schema modules - Fixed schema imports in routes - Updated app/models/__init__.py to properly export SQLAlchemy models - Fixed database imports in route files - App imports and runs correctly
This commit is contained in:
@@ -6,4 +6,24 @@ from app.schemas.auth import (
|
||||
UserResponse,
|
||||
)
|
||||
|
||||
__all__ = ["Token", "UserLogin", "UserRegister", "UserResponse"]
|
||||
# Post schemas
|
||||
from app.schemas.post import CommentCreate, CommentResponse, PostResponse
|
||||
|
||||
# User schemas
|
||||
from app.schemas.user import UserBase, UserStats
|
||||
|
||||
# Feed schemas
|
||||
from app.schemas.feed import FeedResponse
|
||||
|
||||
__all__ = [
|
||||
"Token",
|
||||
"UserLogin",
|
||||
"UserRegister",
|
||||
"UserResponse",
|
||||
"CommentCreate",
|
||||
"CommentResponse",
|
||||
"PostResponse",
|
||||
"UserBase",
|
||||
"UserStats",
|
||||
"FeedResponse",
|
||||
]
|
||||
|
||||
14
app/schemas/feed.py
Normal file
14
app/schemas/feed.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""Feed schemas for SocialPhoto API."""
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.schemas.post import PostResponse
|
||||
|
||||
|
||||
class FeedResponse(BaseModel):
|
||||
"""Response model for feed."""
|
||||
posts: List[PostResponse]
|
||||
total: int
|
||||
limit: int
|
||||
offset: int
|
||||
48
app/schemas/post.py
Normal file
48
app/schemas/post.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Post schemas for SocialPhoto API."""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class PostCreate(BaseModel):
|
||||
"""Request model for creating a post."""
|
||||
caption: Optional[str] = ""
|
||||
|
||||
|
||||
class PostResponse(BaseModel):
|
||||
"""Response model for post data."""
|
||||
id: int
|
||||
user_id: int
|
||||
username: str
|
||||
image_url: str
|
||||
caption: str
|
||||
likes_count: int
|
||||
dislikes_count: int
|
||||
comments_count: int
|
||||
created_at: datetime
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class PostDetail(PostResponse):
|
||||
"""Detailed post response with user info."""
|
||||
user: "UserResponse" # noqa: F821
|
||||
|
||||
|
||||
class CommentCreate(BaseModel):
|
||||
"""Request model for creating a comment."""
|
||||
content: str = Field(..., min_length=1, max_length=500)
|
||||
|
||||
|
||||
class CommentResponse(BaseModel):
|
||||
"""Response model for comment data."""
|
||||
id: int
|
||||
post_id: int
|
||||
user_id: int
|
||||
username: str
|
||||
content: str
|
||||
likes_count: int
|
||||
created_at: datetime
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
20
app/schemas/user.py
Normal file
20
app/schemas/user.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""User schemas for SocialPhoto API."""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class UserBase(BaseModel):
|
||||
"""Base user model."""
|
||||
username: str
|
||||
email: str
|
||||
avatar_url: Optional[str] = "/static/default-avatar.png"
|
||||
bio: Optional[str] = ""
|
||||
|
||||
|
||||
class UserStats(BaseModel):
|
||||
"""User statistics model."""
|
||||
posts_count: int
|
||||
followers_count: int
|
||||
following_count: int
|
||||
Reference in New Issue
Block a user