From be3ec3fd89d815fd133ccd5f2b5faf6302bcba35 Mon Sep 17 00:00:00 2001 From: Carlos Tello Date: Wed, 7 Oct 2026 19:57:57 -0300 Subject: [PATCH] feat(api): add sheets-inspect endpoint and filter params to sync-sheets --- backend/app/routes/api/dashboard.py | 37 +++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/backend/app/routes/api/dashboard.py b/backend/app/routes/api/dashboard.py index 8ba396c..e0c6583 100644 --- a/backend/app/routes/api/dashboard.py +++ b/backend/app/routes/api/dashboard.py @@ -475,13 +475,25 @@ def get_stats(): @api_dashboard_bp.route('/sync-sheets', methods=['POST']) @jwt_required def sync_google_sheets(): - """Ejecuta la sincronización real con las hojas de cálculo de Google Sheets.""" + """Ejecuta la sincronización real con las hojas de cálculo de Google Sheets con soporte de filtros.""" from app.services.sheets_importer import GoogleSheetsImporter try: data = request.get_json(silent=True) or {} custom_url = data.get('sheets_url') or data.get('base_url') + filter_career = data.get('filter_career') + filter_subject = data.get('filter_subject') + filter_day = data.get('filter_day') + manual_date = data.get('manual_date') + single_date_only = bool(data.get('single_date_only', False)) + importer = GoogleSheetsImporter(base_url=custom_url) - stats = importer.sync() + stats = importer.sync( + filter_career=filter_career, + filter_subject=filter_subject, + filter_day=filter_day, + manual_date=manual_date, + single_date_only=single_date_only + ) return jsonify({ 'status': 'success', 'stats': stats, @@ -493,3 +505,24 @@ def sync_google_sheets(): 'message': str(e) }), 500 +@api_dashboard_bp.route('/sheets-inspect', methods=['GET', 'POST']) +@jwt_required +def inspect_google_sheets(): + """Devuelve metadatos, carreras y materias del Google Sheet online para filtros interactivos.""" + from app.services.sheets_importer import GoogleSheetsImporter + try: + data = request.get_json(silent=True) or {} + custom_url = data.get('sheets_url') or request.args.get('sheets_url') + importer = GoogleSheetsImporter(base_url=custom_url) + metadata = importer.inspect_sheet_content() + return jsonify({ + 'status': 'success', + 'metadata': metadata, + 'source_url': importer.base_url + }), 200 + except Exception as e: + return jsonify({ + 'status': 'error', + 'message': str(e) + }), 500 +