Automated Action 06df0285b1 Implement Blogging Platform API with FastAPI and SQLite
- Set up project structure and dependencies
- Create database models for users, posts, comments, and tags
- Set up Alembic for database migrations
- Implement user authentication (register, login)
- Create CRUD endpoints for blog posts, comments, and tags
- Add health check endpoint
- Set up proper error handling
- Update README with project details and setup instructions
2025-06-02 21:58:50 +00:00

63 lines
1.8 KiB
Python

from typing import List, Optional
from sqlalchemy.orm import Session, joinedload
from app.crud.base import CRUDBase
from app.models.comment import Comment
from app.schemas.comment import CommentCreate, CommentUpdate
class CRUDComment(CRUDBase[Comment, CommentCreate, CommentUpdate]):
def create_with_author(
self, db: Session, *, obj_in: CommentCreate, author_id: int
) -> Comment:
obj_in_data = obj_in.model_dump()
db_obj = Comment(**obj_in_data, author_id=author_id)
db.add(db_obj)
db.commit()
db.refresh(db_obj)
return db_obj
def get_multi_by_author(
self, db: Session, *, author_id: int, skip: int = 0, limit: int = 100
) -> List[Comment]:
return (
db.query(Comment)
.filter(Comment.author_id == author_id)
.offset(skip)
.limit(limit)
.all()
)
def get_multi_by_post(
self, db: Session, *, post_id: int, skip: int = 0, limit: int = 100
) -> List[Comment]:
return (
db.query(Comment)
.filter(Comment.post_id == post_id)
.offset(skip)
.limit(limit)
.all()
)
def get_with_author(self, db: Session, *, id: int) -> Optional[Comment]:
return (
db.query(Comment)
.options(joinedload(Comment.author))
.filter(Comment.id == id)
.first()
)
def get_multi_with_author(
self, db: Session, *, skip: int = 0, limit: int = 100
) -> List[Comment]:
return (
db.query(Comment)
.options(joinedload(Comment.author))
.offset(skip)
.limit(limit)
.all()
)
comment = CRUDComment(Comment)