Skip to content

Commit

Permalink
fix: add order_by parameter to /api/v1/insights route
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Oct 29, 2024
1 parent f5b1de4 commit 2dcf4a7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions robotoff/app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ def on_get(self, req: falcon.Request, resp: falcon.Response):
predictor = req.get_param("predictor")
server_type = get_server_type_from_req(req)
countries: Optional[list[Country]] = get_countries_from_req(req)
order_by: Optional[str] = req.get_param("order_by")

if order_by not in ("random", "popularity", None):
raise falcon.HTTPBadRequest(
description=f"invalid `order_by` value: {order_by}"
)

if keep_types:
# Limit the number of types to prevent slow SQL queries
Expand All @@ -229,6 +235,7 @@ def on_get(self, req: falcon.Request, resp: falcon.Response):
annotation=annotation,
barcode=barcode,
predictor=predictor,
order_by=order_by,
)

offset: int = (page - 1) * count
Expand Down

0 comments on commit 2dcf4a7

Please sign in to comment.