Files
eve_structure/webapp/routes/blueprints.py
2025-08-27 18:55:45 +02:00

35 lines
1.0 KiB
Python

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)})