From: Michael Tremer Date: Mon, 29 Dec 2025 13:59:47 +0000 (+0000) Subject: api: Add endpoint to fetch a single list X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c23cc640adcc2823fe2ec1b3fdd8cff41d0d27c2;p=dbl.git api: Add endpoint to fetch a single list Signed-off-by: Michael Tremer --- diff --git a/src/dnsbl/api/lists.py b/src/dnsbl/api/lists.py index cb39904..a33d21d 100644 --- a/src/dnsbl/api/lists.py +++ b/src/dnsbl/api/lists.py @@ -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) diff --git a/src/dnsbl/lists.py b/src/dnsbl/lists.py index 6b5de5a..44c47df 100644 --- a/src/dnsbl/lists.py +++ b/src/dnsbl/lists.py @@ -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