Middelware update and footer content
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 39s

This commit is contained in:
2024-12-20 22:35:39 +01:00
parent 18181d7ce8
commit d58e5b0d12
10 changed files with 192 additions and 32 deletions

View File

@@ -3,6 +3,7 @@ import json
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi.responses import JSONResponse
class CategoryController:
@@ -22,6 +23,10 @@ class CategoryController:
methods=["GET"],
response_class=HTMLResponse,
)
self.router.add_api_route(
"/categories", self.list_categories, methods = ["GET"], response_class = JSONResponse
)
def _load_data(self, data_file):
"""Load JSON data from a file."""
with open(data_file, "r", encoding="utf-8") as file:
@@ -53,3 +58,11 @@ class CategoryController:
},
)
return HTMLResponse("Kategori ikke fundet", status_code=404)
async def list_categories(self, request: Request):
"""Return a list of all categories with their name and path."""
categories = [
{ "name": category["name"], "path": category["path"] }
for category in self.data.get( "categories", [] )
]
return JSONResponse( content = categories )