Skip to content

Commit

Permalink
fix: allow to filter insights by campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Dec 3, 2024
1 parent 20fd107 commit f31cebd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion doc/references/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ paths:
- $ref: "#/components/parameters/insight_order_by"
- $ref: "#/components/parameters/count"
- $ref: "#/components/parameters/page"
- $ref: "#/components/parameters/campaigns"
responses:
"200":
description: ""
Expand Down Expand Up @@ -1424,7 +1425,8 @@ components:
name: campaigns
in: query
description: Filter by annotation campaigns (the insight must have all the campaigns)
An annotation campaigns allows to only retrieve questions about selected products, based on arbitrary criteria
An annotation campaign allows to only retrieve questions or insights based on arbitrary criteria
defined during insight import.
schema:
type: string
example: agribalyse-category
Expand Down
6 changes: 4 additions & 2 deletions robotoff/app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ def on_get(self, req: falcon.Request, resp: falcon.Response):
brands = req.get_param_as_list("brands") or None
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")
countries: list[Country] | None = get_countries_from_req(req)
order_by: str | None = req.get_param("order_by")
campaigns: list[str] | None = req.get_param_as_list("campaigns") or None

Check warning on line 213 in robotoff/app/api.py

View check run for this annotation

Codecov / codecov/patch

robotoff/app/api.py#L211-L213

Added lines #L211 - L213 were not covered by tests

if order_by not in ("random", "popularity", None):
raise falcon.HTTPBadRequest(
Expand All @@ -236,6 +237,7 @@ def on_get(self, req: falcon.Request, resp: falcon.Response):
barcode=barcode,
predictor=predictor,
order_by=order_by,
campaigns=campaigns,
)

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

0 comments on commit f31cebd

Please sign in to comment.