Add build endpoint
This commit is contained in:
@@ -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()
|
||||
|
||||
22
backend/app/services/builds.py
Normal file
22
backend/app/services/builds.py
Normal file
@@ -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)}
|
||||
Reference in New Issue
Block a user