refactor: decouple — blueprint'ы + CSS/HTML разделение (по шаблону app-autotest)

This commit is contained in:
2026-07-31 22:16:22 +04:00
parent 6a0d5d00a2
commit 944238d224
16 changed files with 803 additions and 464 deletions
+62
View File
@@ -0,0 +1,62 @@
"""
routes/services_routes.py — эндпоинты сервисов.
Blueprint "services" с префиксом /api/v1/svc/services.
GET /services — список всех загруженных сервисов
GET /services/<id> — детали конкретного сервиса (список операций)
"""
from flask import Blueprint, jsonify
from config.loader import SERVICES
bp = Blueprint("services", __name__, url_prefix="/api/v1/svc/services")
@bp.route("", methods=["GET"])
@bp.route("/", methods=["GET"])
def list_services():
"""GET /api/v1/svc/services — список всех сервисов.
Возвращает {results: [{svcId, svc, svcShort}, ...]}.
Формат совпадает с реальным Nubes API:
svcId — числовой ID сервиса (1, 90, 91, ...)
svc — человекочитаемое имя (Болванка, PostgreSQL, ...)
svcShort — короткое имя (dummy, postgres, ...)
"""
results = []
for svc_id, svc_def in SERVICES.items():
results.append({
"svcId": svc_id,
"svc": svc_def.get("service_display_name", ""),
"svcShort": svc_def.get("service_short_name", svc_def.get("name", "")),
})
return jsonify({"results": results})
@bp.route("/<int:svc_id>", methods=["GET"])
def get_service(svc_id):
"""GET /api/v1/svc/services/{id} — детали сервиса.
Возвращает {svc: {svc, svcShort, operations: [{svcOperationId, operation}]}}.
Если сервис не найден — 404 с JSON-ошибкой.
"""
svc_def = SERVICES.get(svc_id)
if not svc_def:
return jsonify({"error": "service not found"}), 404
# Собрать список операций сервиса (create, modify, delete, suspend, ...)
ops = []
for op in svc_def.get("operations", []):
ops.append({
"svcOperationId": op["svcOperationId"],
"operation": op["operation"],
})
return jsonify({
"svc": {
"svc": svc_def.get("service_display_name", ""),
"svcShort": svc_def.get("service_short_name", svc_def.get("name", "")),
"operations": ops,
}
})