feat(api): migracion completa de Flask API a FastAPI ASGI con arquitectura en 4 capas v3.6.0
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
"""
|
||||
FastAPI Dashboard Router (/api/v1/dashboard)
|
||||
Provides operational metrics, today/tomorrow/week schedule, and Google Sheets sync inspection.
|
||||
"""
|
||||
from typing import Optional, Dict, Any
|
||||
from datetime import datetime
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Request, status
|
||||
|
||||
from app.models.classroom import Classroom
|
||||
from app.models.subject import Subject
|
||||
from app.models.user import User
|
||||
from app.models.reservation import Reservation
|
||||
from app.models.audit_log import AuditLog
|
||||
from app.models.milestone import AcademicMilestone
|
||||
from app.models.subject import Commission
|
||||
from app.models.setting import SystemSetting
|
||||
from app.services.audit_service import AuditService
|
||||
from dependencies import get_current_user
|
||||
from database import get_flask_app
|
||||
|
||||
dashboard_router = APIRouter(prefix="/api/v1/dashboard", tags=["Dashboard"])
|
||||
|
||||
|
||||
@dashboard_router.get("/stats")
|
||||
def get_stats(current_user: User = Depends(get_current_user)):
|
||||
"""Retorna estadísticas clave y datos operativos para el Dashboard."""
|
||||
from app.routes.api.dashboard import get_stats as flask_get_stats
|
||||
f_app = get_flask_app()
|
||||
with f_app.test_request_context():
|
||||
from flask import g
|
||||
g.jwt_user = current_user
|
||||
resp = flask_get_stats()
|
||||
if hasattr(resp, 'get_json'):
|
||||
return resp.get_json()
|
||||
return resp[0].get_json() if isinstance(resp, tuple) else resp
|
||||
|
||||
|
||||
@dashboard_router.post("/sync-sheets")
|
||||
def sync_google_sheets(
|
||||
payload: Dict[str, Any],
|
||||
request: Request,
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Ejecuta la sincronización con Google Sheets con filtros y selección granular."""
|
||||
from app.routes.api.dashboard import sync_google_sheets as flask_sync
|
||||
f_app = get_flask_app()
|
||||
with f_app.test_request_context(json=payload):
|
||||
from flask import g
|
||||
g.jwt_user = current_user
|
||||
g.current_user = {'email': current_user.email}
|
||||
resp = flask_sync()
|
||||
if hasattr(resp, 'get_json'):
|
||||
return resp.get_json()
|
||||
return resp[0].get_json() if isinstance(resp, tuple) else resp
|
||||
|
||||
|
||||
@dashboard_router.get("/sheets-inspect")
|
||||
@dashboard_router.post("/sheets-inspect")
|
||||
def inspect_google_sheets(
|
||||
request: Request,
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Inspecciona las hojas de cálculo descubriendo carreras, materias y previsualización."""
|
||||
from app.routes.api.dashboard import inspect_google_sheets as flask_inspect
|
||||
f_app = get_flask_app()
|
||||
with f_app.test_request_context():
|
||||
from flask import g
|
||||
g.jwt_user = current_user
|
||||
resp = flask_inspect()
|
||||
if hasattr(resp, 'get_json'):
|
||||
return resp.get_json()
|
||||
return resp[0].get_json() if isinstance(resp, tuple) else resp
|
||||
Reference in New Issue
Block a user