[ВОЛК] добавление закладки Площадки
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2025-12-25 20:15:02 +03:00
parent 26d12a4758
commit e03fb9a872
2 changed files with 484 additions and 32 deletions
+82
View File
@@ -1092,6 +1092,88 @@ def api_load_categories():
log_event(error_msg)
return jsonify({'success': False, 'error': error_msg}), 500
@bp.route('/api/categories')
@login_required
def api_categories():
"""Получает список всех категорий (площадок) из таблицы categories"""
db = get_db()
try:
with db.conn.cursor() as cursor:
cursor.execute("""
SELECT AUTO_ID, ID, TITLE, description
FROM categories
ORDER BY TITLE, ID
""")
categories = cursor.fetchall()
categories_list = []
for cat in categories:
categories_list.append({
'auto_id': cat['AUTO_ID'],
'id': cat['ID'],
'title': cat['TITLE'] or '',
'description': cat['description'] or ''
})
return jsonify(categories_list)
except Exception as e:
return jsonify({'error': str(e)}), 500
finally:
db.close()
@bp.route('/api/categories/<category_id>')
@login_required
def api_category_details(category_id):
"""Получает детали категории по ID"""
db = get_db()
try:
with db.conn.cursor() as cursor:
cursor.execute("""
SELECT AUTO_ID, ID, TITLE, description
FROM categories
WHERE ID = %s
""", (category_id,))
category = cursor.fetchone()
if not category:
return jsonify({'error': 'Category not found'}), 404
# Получаем количество событий для этой категории
cursor.execute("""
SELECT COUNT(*) as event_count
FROM events
WHERE unit_name = %s
""", (category_id,))
event_count_result = cursor.fetchone()
event_count = event_count_result['event_count'] if event_count_result else 0
return jsonify({
'auto_id': category['AUTO_ID'],
'id': category['ID'],
'title': category['TITLE'] or '',
'description': category['description'] or '',
'event_count': event_count
})
except Exception as e:
return jsonify({'error': str(e)}), 500
finally:
db.close()
@bp.route('/api/events/count')
@login_required
def api_events_count():
"""Получает количество событий в таблице events"""
db = get_db()
try:
with db.conn.cursor() as cursor:
cursor.execute("SELECT COUNT(*) as count FROM events")
result = cursor.fetchone()
return jsonify({'count': result['count'] if result else 0})
except Exception as e:
return jsonify({'error': str(e)}), 500
finally:
db.close()
@bp.route('/api/run_volk_rescan', methods=['POST'])
@login_required
def api_run_volk_rescan():