Loads and loads of data

This commit is contained in:
2024-12-12 23:30:19 +01:00
parent 46a1951586
commit c751d0b072
69 changed files with 2194 additions and 101 deletions

View File

@@ -6,18 +6,13 @@ from fastapi.templating import Jinja2Templates
class CategoryController:
def __init__(self):
def __init__(self,data_file="generated_data.json"):
"""Initialize the controller."""
self.router = APIRouter()
self.templates = Jinja2Templates(directory="templates")
self.data = self._load_mock_data()
self.data = self._load_data( data_file )
self._add_routes()
def _load_mock_data(self):
"""Load mock data from a JSON file."""
with open("mock_data.json") as file:
return json.load(file)
def _add_routes(self):
"""Add routes to the router."""
self.router.add_api_route("/", self.get_index, methods=["GET"], response_class=HTMLResponse)
@@ -27,6 +22,10 @@ class CategoryController:
methods=["GET"],
response_class=HTMLResponse,
)
def _load_data(self, data_file):
"""Load JSON data from a file."""
with open(data_file, "r", encoding="utf-8") as file:
return json.load(file)
async def get_index(self, request: Request):
"""Index route."""