Add Reddit monitoring bot — backend, frontend, and Docker config
Python/FastAPI backend with PostgreSQL for collecting Reddit data via public .json endpoints. React/Vite dashboard for analytics. Docker Compose setup with API and worker services connecting to shared PostgreSQL. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
39
backend/routers/authors.py
Normal file
39
backend/routers/authors.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from datetime import datetime
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from backend.database import get_db
|
||||
from backend.services import author_service
|
||||
|
||||
router = APIRouter(prefix="/authors", tags=["authors"])
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def list_authors(
|
||||
subreddit_id: int | None = None,
|
||||
sort_by: str = Query("total_comments", pattern="^(total_posts|total_comments)$"),
|
||||
sort_order: str = Query("desc", pattern="^(asc|desc)$"),
|
||||
since: datetime | None = None,
|
||||
until: datetime | None = None,
|
||||
page: int = Query(1, ge=1),
|
||||
per_page: int = Query(25, ge=1, le=100),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
authors, total = await author_service.list_authors(
|
||||
db, subreddit_id, sort_by, sort_order, since, until, page, per_page
|
||||
)
|
||||
return {
|
||||
"data": authors,
|
||||
"total": total,
|
||||
"page": page,
|
||||
"per_page": per_page,
|
||||
"pages": (total + per_page - 1) // per_page if per_page else 0,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/{author_id}")
|
||||
async def get_author(author_id: int, db: AsyncSession = Depends(get_db)):
|
||||
author = await author_service.get_author(db, author_id)
|
||||
if not author:
|
||||
raise HTTPException(status_code=404, detail="Author not found")
|
||||
return author
|
||||
Reference in New Issue
Block a user