feat: Complete ATLAS system installation and API fixes
## 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>
This commit is contained in:
@@ -31,7 +31,7 @@ from app.services.ubicacion_service import UbicacionService
|
||||
router = APIRouter(prefix="/vehiculos", tags=["Vehiculos"])
|
||||
|
||||
|
||||
@router.get("", response_model=List[VehiculoResumen])
|
||||
@router.get("")
|
||||
async def listar_vehiculos(
|
||||
activo: Optional[bool] = None,
|
||||
en_servicio: Optional[bool] = None,
|
||||
@@ -39,6 +39,8 @@ async def listar_vehiculos(
|
||||
buscar: Optional[str] = None,
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(50, ge=1, le=100),
|
||||
page: int = Query(None, ge=1),
|
||||
pageSize: int = Query(None, ge=1, le=100),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: Usuario = Depends(get_current_user),
|
||||
):
|
||||
@@ -54,8 +56,12 @@ async def listar_vehiculos(
|
||||
limit: Límite de registros.
|
||||
|
||||
Returns:
|
||||
Lista de vehículos.
|
||||
Lista de vehículos paginada.
|
||||
"""
|
||||
# Handle pagination params
|
||||
actual_limit = pageSize or limit
|
||||
actual_skip = ((page - 1) * actual_limit) if page else skip
|
||||
|
||||
query = select(Vehiculo)
|
||||
|
||||
if activo is not None:
|
||||
@@ -70,14 +76,55 @@ async def listar_vehiculos(
|
||||
(Vehiculo.placa.ilike(f"%{buscar}%"))
|
||||
)
|
||||
|
||||
query = query.offset(skip).limit(limit).order_by(Vehiculo.nombre)
|
||||
# Get total count
|
||||
count_query = select(func.count()).select_from(query.subquery())
|
||||
total_result = await db.execute(count_query)
|
||||
total = total_result.scalar() or 0
|
||||
|
||||
query = query.offset(actual_skip).limit(actual_limit).order_by(Vehiculo.nombre)
|
||||
|
||||
result = await db.execute(query)
|
||||
vehiculos = result.scalars().all()
|
||||
|
||||
return {
|
||||
"items": [VehiculoResumen.model_validate(v) for v in vehiculos],
|
||||
"total": total,
|
||||
"page": (actual_skip // actual_limit) + 1,
|
||||
"pageSize": actual_limit,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/all")
|
||||
async def listar_todos_vehiculos(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: Usuario = Depends(get_current_user),
|
||||
):
|
||||
"""
|
||||
Lista todos los vehículos activos (sin paginación).
|
||||
Para uso en mapas, selectores, etc.
|
||||
"""
|
||||
result = await db.execute(
|
||||
select(Vehiculo)
|
||||
.where(Vehiculo.activo == True)
|
||||
.order_by(Vehiculo.nombre)
|
||||
)
|
||||
vehiculos = result.scalars().all()
|
||||
return [VehiculoResumen.model_validate(v) for v in vehiculos]
|
||||
|
||||
|
||||
@router.get("/ubicaciones/actuales", response_model=List[VehiculoUbicacionActual])
|
||||
async def obtener_ubicaciones_actuales(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: Usuario = Depends(get_current_user),
|
||||
):
|
||||
"""
|
||||
Obtiene las ubicaciones actuales de todos los vehículos.
|
||||
Alias para /ubicaciones.
|
||||
"""
|
||||
ubicacion_service = UbicacionService(db)
|
||||
return await ubicacion_service.obtener_ubicaciones_flota()
|
||||
|
||||
|
||||
@router.get("/ubicaciones", response_model=List[VehiculoUbicacionActual])
|
||||
async def obtener_ubicaciones_flota(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
@@ -93,6 +140,54 @@ async def obtener_ubicaciones_flota(
|
||||
return await ubicacion_service.obtener_ubicaciones_flota()
|
||||
|
||||
|
||||
@router.get("/fleet/stats")
|
||||
async def obtener_estadisticas_flota(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: Usuario = Depends(get_current_user),
|
||||
):
|
||||
"""
|
||||
Obtiene estadísticas generales de la flota.
|
||||
|
||||
Returns:
|
||||
Estadísticas de la flota.
|
||||
"""
|
||||
# Total de vehículos
|
||||
result = await db.execute(select(func.count(Vehiculo.id)))
|
||||
total = result.scalar() or 0
|
||||
|
||||
# Activos
|
||||
result = await db.execute(
|
||||
select(func.count(Vehiculo.id)).where(Vehiculo.activo == True)
|
||||
)
|
||||
activos = result.scalar() or 0
|
||||
|
||||
# Inactivos
|
||||
inactivos = total - activos
|
||||
|
||||
# En servicio
|
||||
result = await db.execute(
|
||||
select(func.count(Vehiculo.id)).where(Vehiculo.en_servicio == True)
|
||||
)
|
||||
en_servicio = result.scalar() or 0
|
||||
|
||||
# Alertas activas
|
||||
result = await db.execute(
|
||||
select(func.count(Alerta.id)).where(Alerta.atendida == False)
|
||||
)
|
||||
alertas_activas = result.scalar() or 0
|
||||
|
||||
return {
|
||||
"total": total,
|
||||
"activos": activos,
|
||||
"inactivos": inactivos,
|
||||
"mantenimiento": 0,
|
||||
"enMovimiento": 0,
|
||||
"detenidos": en_servicio,
|
||||
"sinSenal": 0,
|
||||
"alertasActivas": alertas_activas,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/{vehiculo_id}", response_model=VehiculoConRelaciones)
|
||||
async def obtener_vehiculo(
|
||||
vehiculo_id: int,
|
||||
|
||||
Reference in New Issue
Block a user