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:
47
backend/routers/subreddits.py
Normal file
47
backend/routers/subreddits.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from backend.database import get_db
|
||||
from backend.schemas.subreddit import SubredditCreate, SubredditUpdate, SubredditResponse
|
||||
from backend.services import subreddit_service
|
||||
|
||||
router = APIRouter(prefix="/subreddits", tags=["subreddits"])
|
||||
|
||||
|
||||
@router.get("", response_model=list[SubredditResponse])
|
||||
async def list_subreddits(db: AsyncSession = Depends(get_db)):
|
||||
return await subreddit_service.list_subreddits(db)
|
||||
|
||||
|
||||
@router.post("", response_model=SubredditResponse, status_code=201)
|
||||
async def create_subreddit(body: SubredditCreate, db: AsyncSession = Depends(get_db)):
|
||||
sub = await subreddit_service.create_subreddit(db, body.name)
|
||||
data = {c.name: getattr(sub, c.name) for c in sub.__table__.columns}
|
||||
data["post_count"] = 0
|
||||
return data
|
||||
|
||||
|
||||
@router.get("/{subreddit_id}", response_model=SubredditResponse)
|
||||
async def get_subreddit(subreddit_id: int, db: AsyncSession = Depends(get_db)):
|
||||
sub = await subreddit_service.get_subreddit(db, subreddit_id)
|
||||
if not sub:
|
||||
raise HTTPException(status_code=404, detail="Subreddit not found")
|
||||
return sub
|
||||
|
||||
|
||||
@router.patch("/{subreddit_id}", response_model=SubredditResponse)
|
||||
async def update_subreddit(
|
||||
subreddit_id: int, body: SubredditUpdate, db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
sub = await subreddit_service.update_subreddit(db, subreddit_id, body.is_active)
|
||||
if not sub:
|
||||
raise HTTPException(status_code=404, detail="Subreddit not found")
|
||||
result = await subreddit_service.get_subreddit(db, subreddit_id)
|
||||
return result
|
||||
|
||||
|
||||
@router.delete("/{subreddit_id}", status_code=204)
|
||||
async def delete_subreddit(subreddit_id: int, db: AsyncSession = Depends(get_db)):
|
||||
deleted = await subreddit_service.delete_subreddit(db, subreddit_id)
|
||||
if not deleted:
|
||||
raise HTTPException(status_code=404, detail="Subreddit not found")
|
||||
Reference in New Issue
Block a user