enable pagination in /truths
Some checks failed
Build and Publish / build_and_publish (push) Has been cancelled

This commit is contained in:
Nexus 2024-07-14 01:33:48 +01:00
parent d22d439a4f
commit 5fbd425452
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -96,7 +96,12 @@ truth_router = APIRouter(
@truth_router.get("", response_model=list[TruthPayload])
def get_all_truths(rich: bool = True, db: redis.Redis = Depends(get_db_factory())):
def get_all_truths(
rich: bool = True,
limit: int = -1,
page: int = 0,
db: redis.Redis = Depends(get_db_factory())
):
"""Retrieves all stored truths"""
keys = db.keys()
if rich is False:
@ -105,13 +110,15 @@ def get_all_truths(rich: bool = True, db: redis.Redis = Depends(get_db_factory()
for key in keys
]
truths = [json.loads(db.get(key)) for key in keys]
if limit >= 0:
return truths[page * limit:(page + 1) * limit]
return truths
@truth_router.get("/all", deprecated=True, response_model=list[TruthPayload])
def get_all_truths_deprecated(response: JSONResponse, rich: bool = True, db: redis.Redis = Depends(get_db_factory())):
"""DEPRECATED - USE get_all_truths INSTEAD"""
return get_all_truths(rich, db)
return get_all_truths(rich=rich, db=db)
@truth_router.get("/{truth_id}", response_model=TruthPayload)