first commit
This commit is contained in:
34
webapp/routes/blueprints.py
Normal file
34
webapp/routes/blueprints.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from __future__ import annotations
|
||||
from flask import Blueprint, request, jsonify
|
||||
from webapp.services.blueprints import (
|
||||
resolve_blueprint_id,
|
||||
resolve_blueprint_id_by_product_id,
|
||||
)
|
||||
|
||||
bp = Blueprint("blueprints_api", __name__)
|
||||
|
||||
@bp.get("/api/blueprint_id")
|
||||
def api_blueprint_id():
|
||||
"""
|
||||
Liefert die Blueprint-TypeID.
|
||||
Query-Parameter:
|
||||
- name: Produktname (z. B. "Structure Market Network")
|
||||
- productTypeId: Produkt-TypeID (optional, wenn 'name' fehlt)
|
||||
Antwort: { ok: true, blueprint_type_id: 12345 } oder { ok:false, error: "..." }
|
||||
"""
|
||||
name = (request.args.get("name") or "").strip()
|
||||
pid = request.args.get("productTypeId")
|
||||
|
||||
bp_tid = None
|
||||
if name:
|
||||
bp_tid = resolve_blueprint_id(name)
|
||||
elif pid:
|
||||
try:
|
||||
bp_tid = resolve_blueprint_id_by_product_id(int(pid))
|
||||
except Exception:
|
||||
bp_tid = None
|
||||
|
||||
if not bp_tid:
|
||||
return jsonify({"ok": False, "error": "not-found"}), 404
|
||||
|
||||
return jsonify({"ok": True, "blueprint_type_id": int(bp_tid)})
|
||||
Reference in New Issue
Block a user