File size: 1,018 Bytes
6a8626d dd4fff8 6a8626d 0f9f853 72f4cb5 6e73939 0f9f853 6e73939 0f9f853 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
"""
Defines Flask routes for handling call by category
This module contains API endpoints for managing and retrieving categories
from the MongoDB database.
Routes:
- GET /category: Fetch all categories.
"""
from fastapi import APIRouter
from fastapi.responses import JSONResponse
from controllers.category import get_categories # pylint: disable=import-error
router = APIRouter(prefix="/category", tags=["category"])
@router.get("")
async def fetch_categories() -> JSONResponse:
"""
Handles GET requests to retrieve all categories.
Returns:
list[dict]: JSON response containing categories and their associated sites.
"""
try:
category_data = get_categories()
return JSONResponse(content=category_data)
except (ConnectionError, TimeoutError, ValueError) as e:
return JSONResponse(content={"error": str(e)}, status_code=400)
except Exception as e: #pylint: disable=broad-except
return JSONResponse(content={"error": str(e)}, status_code=500)
|