generated from hjess/PythonTemplateProject
Loads and loads of data
This commit is contained in:
@@ -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."""
|
||||
|
||||
@@ -15,7 +15,7 @@ class DynamicController:
|
||||
|
||||
def _load_mock_data(self):
|
||||
"""Load mock data from a JSON file."""
|
||||
with open("mock_data.json") as file:
|
||||
with open("generated_data.json") as file:
|
||||
return json.load(file)
|
||||
|
||||
def _add_dynamic_routes(self):
|
||||
|
||||
Reference in New Issue
Block a user