From 526433afba948776550cde73ef61aacf366da75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sat, 13 Nov 2021 15:03:21 +0100 Subject: [PATCH] [pricelist] serviceside filtering for ingredients --- flaschengeist/plugins/pricelist/__init__.py | 10 +++++++++- .../plugins/pricelist/pricelist_controller.py | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/flaschengeist/plugins/pricelist/__init__.py b/flaschengeist/plugins/pricelist/__init__.py index 3e4c71b..2239727 100644 --- a/flaschengeist/plugins/pricelist/__init__.py +++ b/flaschengeist/plugins/pricelist/__init__.py @@ -220,15 +220,23 @@ def get_drinks(identifier=None): offset = request.args.get("offset") search_name = request.args.get("search_name") search_key = request.args.get("search_key") + ingredient = request.args.get("ingredient", type=bool) try: if limit is not None: limit = int(limit) if offset is not None: offset = int(offset) + if ingredient is not None: + ingredient = bool(ingredient) except ValueError: raise BadRequest drinks, count = pricelist_controller.get_drinks( - public=public, limit=limit, offset=offset, search_name=search_name, search_key=search_key + public=public, + limit=limit, + offset=offset, + search_name=search_name, + search_key=search_key, + ingredient=ingredient, ) logger.debug(f"GET drink {drinks}, {count}") # return jsonify({"drinks": drinks, "count": count}) diff --git a/flaschengeist/plugins/pricelist/pricelist_controller.py b/flaschengeist/plugins/pricelist/pricelist_controller.py index 5f8154c..b32a26d 100644 --- a/flaschengeist/plugins/pricelist/pricelist_controller.py +++ b/flaschengeist/plugins/pricelist/pricelist_controller.py @@ -131,12 +131,14 @@ def _create_public_drink(drink): return None -def get_drinks(name=None, public=False, limit=None, offset=None, search_name=None, search_key=None): +def get_drinks(name=None, public=False, limit=None, offset=None, search_name=None, search_key=None, ingredient=False): count = None if name: query = Drink.query.filter(Drink.name.contains(name)) else: query = Drink.query + if ingredient: + query = query.filter(Drink.cost_per_volume >= 0) if search_name: if search_key == "name": query = query.filter(Drink.name.contains(search_name))