Files
ATLAS/backend/app/api/v1/mantenimiento.py
ATLAS Admin e59aa2a742 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>
2026-01-25 03:04:23 +00:00

93 lines
3.2 KiB
Python

"""Endpoints para gestión de mantenimiento."""
from typing import List, Optional
from datetime import datetime, timedelta, timezone
from fastapi import APIRouter, Depends, Query, HTTPException
from sqlalchemy import select, and_
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.mantenimiento import Mantenimiento
router = APIRouter(prefix="/mantenimiento", tags=["Mantenimiento"])
@router.get("")
async def listar_mantenimientos(
vehiculo_id: Optional[int] = None,
estado: Optional[str] = None,
skip: int = Query(0, ge=0),
limit: int = Query(50, ge=1, le=100),
db: AsyncSession = Depends(get_db),
current_user: Usuario = Depends(get_current_user),
):
"""Lista los mantenimientos."""
query = select(Mantenimiento)
if vehiculo_id:
query = query.where(Mantenimiento.vehiculo_id == vehiculo_id)
if estado:
query = query.where(Mantenimiento.estado == estado)
query = query.offset(skip).limit(limit).order_by(Mantenimiento.fecha_programada.desc())
result = await db.execute(query)
items = result.scalars().all()
return {"items": [{"id": m.id, "vehiculo_id": m.vehiculo_id, "tipo": m.tipo_mantenimiento_id,
"fecha_programada": m.fecha_programada, "estado": m.estado} for m in items],
"total": len(items)}
@router.get("/proximos")
async def obtener_proximos(
dias: int = 30,
db: AsyncSession = Depends(get_db),
current_user: Usuario = Depends(get_current_user),
):
"""Obtiene mantenimientos próximos."""
ahora = datetime.now(timezone.utc)
limite = ahora + timedelta(days=dias)
query = select(Mantenimiento).where(
and_(
Mantenimiento.fecha_programada >= ahora,
Mantenimiento.fecha_programada <= limite,
Mantenimiento.estado == 'pendiente'
)
).order_by(Mantenimiento.fecha_programada)
result = await db.execute(query)
items = result.scalars().all()
return [{"id": m.id, "vehiculo_id": m.vehiculo_id, "tipo": m.tipo_mantenimiento_id,
"fecha_programada": m.fecha_programada} for m in items]
@router.get("/vencidos")
async def obtener_vencidos(
db: AsyncSession = Depends(get_db),
current_user: Usuario = Depends(get_current_user),
):
"""Obtiene mantenimientos vencidos."""
ahora = datetime.now(timezone.utc)
query = select(Mantenimiento).where(
and_(
Mantenimiento.fecha_programada < ahora,
Mantenimiento.estado == 'pendiente'
)
).order_by(Mantenimiento.fecha_programada)
result = await db.execute(query)
items = result.scalars().all()
return [{"id": m.id, "vehiculo_id": m.vehiculo_id, "tipo": m.tipo_mantenimiento_id,
"fecha_programada": m.fecha_programada} for m in items]
@router.post("")
async def crear_mantenimiento(
data: dict,
db: AsyncSession = Depends(get_db),
current_user: Usuario = Depends(get_current_user),
):
"""Crea un nuevo mantenimiento."""
mant = Mantenimiento(**data)
db.add(mant)
await db.commit()
await db.refresh(mant)
return {"id": mant.id}