From 6f98c86ea7479bb6e5f3a43160f72cbac5592f25 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 9 Jun 2024 16:59:33 +0100 Subject: [PATCH] Fix partial fetching --- src/server.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/server.py b/src/server.py index 5e3eaab..2e14ba3 100644 --- a/src/server.py +++ b/src/server.py @@ -11,6 +11,8 @@ from fastapi.responses import JSONResponse, Response from fastapi.security import HTTPBasic, HTTPBasicCredentials from pydantic import BaseModel, Field +from symbol import return_stmt + JSON: typing.Union[ str, int, float, bool, None, typing.Dict[str, "JSON"], typing.List["JSON"] ] = typing.Union[ @@ -100,7 +102,10 @@ def get_all_truths(rich: bool = True, db: redis.Redis = Depends(get_db_factory() """Retrieves all stored truths""" keys = db.keys() if rich is False: - return keys + return [ + {"id": key, "content": "", "author": "", "timestamp": 0, "extra": None} + for key in keys + ] truths = [json.loads(db.get(key)) for key in keys] return truths @@ -108,12 +113,7 @@ def get_all_truths(rich: bool = True, db: redis.Redis = Depends(get_db_factory() @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""" - keys = db.keys() - if rich is False: - return keys - truths = [json.loads(db.get(key)) for key in keys] - response.headers["X-Deprecated"] = "true" - return truths + return get_all_truths(rich, db) @truth_router.get("/{truth_id}", response_model=TruthPayload)