## Backend Changes - Add new API endpoints: combustible, pois, mantenimiento, video, configuracion - Fix vehiculos endpoint to return paginated response with items array - Add /vehiculos/all endpoint for non-paginated list - Add /geocercas/all endpoint - Add /alertas/configuracion GET/PUT endpoints - Add /viajes/activos and /viajes/iniciar endpoints - Add /reportes/stats, /reportes/templates, /reportes/preview endpoints - Add /conductores/all and /conductores/disponibles endpoints - Update router.py to include all new modules ## Frontend Changes - Fix authentication token handling (snake_case vs camelCase) - Update vehiculosApi.listAll to use /vehiculos/all - Fix FuelGauge component usage in Combustible page - Fix chart component exports (named + default exports) - Update API client for proper token refresh ## Infrastructure - Rename services from ADAN to ATLAS - Configure Cloudflare tunnel for atlas.consultoria-as.com - Update systemd service files - Configure PostgreSQL with TimescaleDB - Configure Redis, Mosquitto, Traccar, MediaMTX ## Documentation - Update installation guides - Update API reference - Rename all ADAN references to ATLAS Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
"""Endpoints para gestión de POIs (Puntos de Interés)."""
|
|
|
|
from typing import List, Optional
|
|
from fastapi import APIRouter, Depends, Query, HTTPException, status
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.core.database import get_db
|
|
from app.core.security import get_current_user
|
|
from app.models.usuario import Usuario
|
|
from app.models.poi import POI
|
|
|
|
router = APIRouter(prefix="/pois", tags=["POIs"])
|
|
|
|
|
|
@router.get("")
|
|
async def listar_pois(
|
|
categoria: Optional[str] = None,
|
|
activo: Optional[bool] = True,
|
|
skip: int = Query(0, ge=0),
|
|
limit: int = Query(100, ge=1, le=500),
|
|
db: AsyncSession = Depends(get_db),
|
|
current_user: Usuario = Depends(get_current_user),
|
|
):
|
|
"""Lista los POIs."""
|
|
query = select(POI)
|
|
if categoria:
|
|
query = query.where(POI.categoria == categoria)
|
|
if activo is not None:
|
|
query = query.where(POI.activo == activo)
|
|
query = query.offset(skip).limit(limit)
|
|
result = await db.execute(query)
|
|
pois = result.scalars().all()
|
|
return [{"id": p.id, "nombre": p.nombre, "categoria": p.categoria,
|
|
"latitud": p.latitud, "longitud": p.longitud, "direccion": p.direccion,
|
|
"activo": p.activo} for p in pois]
|
|
|
|
|
|
@router.get("/all")
|
|
async def listar_todos_pois(
|
|
db: AsyncSession = Depends(get_db),
|
|
current_user: Usuario = Depends(get_current_user),
|
|
):
|
|
"""Lista todos los POIs activos."""
|
|
result = await db.execute(select(POI).where(POI.activo == True))
|
|
pois = result.scalars().all()
|
|
return [{"id": p.id, "nombre": p.nombre, "categoria": p.categoria,
|
|
"latitud": p.latitud, "longitud": p.longitud, "direccion": p.direccion} for p in pois]
|
|
|
|
|
|
@router.post("")
|
|
async def crear_poi(
|
|
data: dict,
|
|
db: AsyncSession = Depends(get_db),
|
|
current_user: Usuario = Depends(get_current_user),
|
|
):
|
|
"""Crea un nuevo POI."""
|
|
poi = POI(**data)
|
|
db.add(poi)
|
|
await db.commit()
|
|
await db.refresh(poi)
|
|
return {"id": poi.id, "nombre": poi.nombre}
|
|
|
|
|
|
@router.get("/{poi_id}")
|
|
async def obtener_poi(
|
|
poi_id: int,
|
|
db: AsyncSession = Depends(get_db),
|
|
current_user: Usuario = Depends(get_current_user),
|
|
):
|
|
"""Obtiene un POI por ID."""
|
|
result = await db.execute(select(POI).where(POI.id == poi_id))
|
|
poi = result.scalar_one_or_none()
|
|
if not poi:
|
|
raise HTTPException(status_code=404, detail="POI no encontrado")
|
|
return {"id": poi.id, "nombre": poi.nombre, "categoria": poi.categoria,
|
|
"latitud": poi.latitud, "longitud": poi.longitud}
|