Files
three_60/backend/api/v1/cellsites/__init__.py
2026-04-01 12:40:40 -04:00

33 lines
912 B
Python

from fastapi import APIRouter
import database as db
from typing import Any
from logger import get_logger
logger = get_logger(__name__)
router = APIRouter(prefix="/cellsites", tags=["cellsites"])
@router.get("/")
def get_cellsites() -> list[dict[Any, Any]]: # type: ignore
conn = db.connect_to_db()
try:
with db.connect_to_db() as conn:
return db.get_cellsites(conn)
except Exception as e:
logger.error(f"Error fetching cellsites: {e}", exc_info=True)
return []
finally:
conn.close()
@router.get("/{id}")
def get_cellsite(id: int) -> list[dict[str, Any]]: # type: ignore
conn = db.connect_to_db()
try:
with db.connect_to_db() as conn:
return db.get_cellsite(conn, id)
except Exception as e:
logger.error(f"Error fetching cellsite {id}: {e}", exc_info=True)
return []
finally:
conn.close()