]> git.ipfire.org Git - dbl.git/commitdiff
api: Add endpoint to fetch a single list
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Dec 2025 13:59:47 +0000 (13:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 29 Dec 2025 13:59:47 +0000 (13:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/api/lists.py
src/dnsbl/lists.py

index cb399048d37c23c3f2b9a4d3e700e32de6cdddee..a33d21d817e7da31f61210db3ae9b755f0a3f383 100644 (file)
@@ -33,9 +33,22 @@ router = fastapi.APIRouter(
        tags=["Lists"],
 )
 
+def get_list_from_path(list: str = fastapi.Path(...)) -> lists.List:
+       """
+               Fetches a list by its slug
+       """
+       return backend.lists.get_by_slug(list)
+
 @router.get("")
 def get_lists() -> typing.List[lists.List]:
        return [l for l in backend.lists]
 
+@router.get("/{list}")
+def get_list(list = fastapi.Depends(get_list_from_path)) -> lists.List:
+       if not list:
+               raise fastapi.HTTPException(404, "Could not find list")
+
+       return list
+
 # Include our endpoints
 app.include_router(router)
index 6b5de5a9f22895fe3dc2eba30ace9887894a99c2..44c47df7462b4507dd21a347fb3d3e11600586dd 100644 (file)
@@ -109,6 +109,9 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
        def __str__(self):
                return self.name
 
+       def __bool__(self):
+               return True
+
        def __len__(self):
                stmt = (
                        sqlmodel