33 lines
902 B
Python
33 lines
902 B
Python
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)
|