Skip to content

Commit

Permalink
Feature:
Browse files Browse the repository at this point in the history
* Add param to only return the value of an aggregate by its key
  • Loading branch information
aliel committed Feb 19, 2024
1 parent ff3efb7 commit f0ad18c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/aleph/web/controllers/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AggregatesQueryParams(BaseModel):
keys: Optional[List[str]] = None
limit: int = DEFAULT_LIMIT
with_info: bool = False
only_value: bool = False

@validator(
"keys",
Expand Down Expand Up @@ -67,10 +68,19 @@ async def address_aggregate(request: web.Request) -> web.Response:
if not aggregates:
raise web.HTTPNotFound(text="No aggregate found for this address")

if query_params.only_value and len(query_params.keys) == 1:
output = {}
target_key = query_params.keys[0]
for result in aggregates:
output[result[0]] = result[1]

return web.json_response(output[target_key])

output = {
"address": address,
"data": {},
}

info: Dict = {}
data: Dict = {}

Expand Down

0 comments on commit f0ad18c

Please sign in to comment.