FastAPI / routes /category.py
raghavNCI
too many changes, hope this works
f00f379
raw
history blame contribute delete
824 Bytes
import os
from fastapi import APIRouter
from dotenv import load_dotenv
from clients.redis_client import redis_client as r
load_dotenv()
router = APIRouter()
@router.get("/news/category/{category}")
def get_cached_articles_by_category(category: str, limit: int):
try:
article_ids = list(r.smembers(f"category:{category}"))[:limit]
articles = []
for article_id in article_ids:
article_data = r.hgetall(f"article:{article_id}")
if article_data:
articles.append(article_data)
return articles
except Exception as e:
print(f"[ERROR] Failed to fetch cached articles: {e}")
return {"error": "Failed to fetch articles from cache."}
@router.get("/")
async def root():
return {"message": "LucidFeed backend is up and running!"}