diff --git a/backend/app/main.py b/backend/app/main.py index f50c67e..41efe2d 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -4,6 +4,7 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.services.menu import build_menu +from app.services.builds import build_history from app.services.prices import prices_payload, random_price from app.settings import settings @@ -55,3 +56,8 @@ def prices(): @app.get("/prices/{item}") def price_for_item(item: str): return random_price(item) + + +@app.get("/builds") +def builds(): + return build_history() diff --git a/backend/app/services/builds.py b/backend/app/services/builds.py new file mode 100644 index 0000000..14edc14 --- /dev/null +++ b/backend/app/services/builds.py @@ -0,0 +1,22 @@ +import json +from pathlib import Path +from typing import Dict, List + +DATA_DIR = Path(__file__).resolve().parent.parent / "data" + + +def _load_json(filename: str) -> Dict: + path = DATA_DIR / filename + with open(path, encoding="utf-8") as file: + return json.load(file) + + +def _sort_builds(builds: List[Dict]) -> List[Dict]: + return sorted(builds, key=lambda build: build.get("number", 0), reverse=True) + + +def build_history() -> Dict: + """Return Jenkins build history data.""" + history = _load_json("build_history.json") + builds = history.get("builds", []) + return {"builds": _sort_builds(builds)}