From 09fb20dd17e5779a4d14ea88965da93b4e37c710 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Tue, 5 Mar 2024 13:36:34 +0100 Subject: [PATCH] feat(products): new filter by labels_tags (#238) --- app/crud.py | 5 +++++ app/schemas.py | 1 + 2 files changed, 6 insertions(+) diff --git a/app/crud.py b/app/crud.py index 4bdcd48f..e61c161e 100644 --- a/app/crud.py +++ b/app/crud.py @@ -191,6 +191,11 @@ def get_products_query(filters: ProductFilter | None = None): Product.categories_tags.contains([filters.categories_tags__contains]) ) filters.categories_tags__contains = None + if filters.labels_tags__contains: + query = query.filter( + Product.categories_tags.contains([filters.labels_tags__contains]) + ) + filters.labels_tags__contains = None query = filters.filter(query) query = filters.sort(query) return query diff --git a/app/schemas.py b/app/schemas.py index e17fe0aa..14c4ee81 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -452,6 +452,7 @@ class ProductFilter(Filter): source: Optional[Flavor] | None = None product_name__like: Optional[str] | None = None categories_tags__contains: Optional[str] | None = None + labels_tags__contains: Optional[str] | None = None brands__like: Optional[str] | None = None nutriscore_grade: Optional[str] | None = None unique_scans_n__gte: Optional[int] | None = None