update
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Route blueprints for the KSP application."""
|
||||
@@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from app.services.fuel_conversion import convert_value, list_fuel_factors
|
||||
|
||||
|
||||
api_bp = Blueprint("api", __name__, url_prefix="/api/v1")
|
||||
|
||||
|
||||
@api_bp.get("/health")
|
||||
def health() -> tuple[str, int] | tuple[dict[str, str], int] | object:
|
||||
return jsonify({"status": "ok", "service": "ksp-data-hangar"})
|
||||
|
||||
|
||||
@api_bp.get("/fuel-converter/fuels")
|
||||
def fuel_factors() -> object:
|
||||
return jsonify({"fuels": list_fuel_factors()})
|
||||
|
||||
|
||||
@api_bp.route("/fuel-converter/convert", methods=["GET", "POST"])
|
||||
def convert_fuel() -> object:
|
||||
payload = request.get_json(silent=True) or request.args
|
||||
mode = payload.get("mode", "")
|
||||
value = payload.get("value")
|
||||
|
||||
try:
|
||||
result = convert_value(mode=mode, raw_value=value)
|
||||
except ValueError as exc:
|
||||
return jsonify({"error": str(exc)}), 400
|
||||
|
||||
return jsonify(result)
|
||||
+3768
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user