[pricelist] serviceside filtering for ingredients
This commit is contained in:
parent
8fb74358e7
commit
526433afba
|
@ -220,15 +220,23 @@ def get_drinks(identifier=None):
|
||||||
offset = request.args.get("offset")
|
offset = request.args.get("offset")
|
||||||
search_name = request.args.get("search_name")
|
search_name = request.args.get("search_name")
|
||||||
search_key = request.args.get("search_key")
|
search_key = request.args.get("search_key")
|
||||||
|
ingredient = request.args.get("ingredient", type=bool)
|
||||||
try:
|
try:
|
||||||
if limit is not None:
|
if limit is not None:
|
||||||
limit = int(limit)
|
limit = int(limit)
|
||||||
if offset is not None:
|
if offset is not None:
|
||||||
offset = int(offset)
|
offset = int(offset)
|
||||||
|
if ingredient is not None:
|
||||||
|
ingredient = bool(ingredient)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise BadRequest
|
raise BadRequest
|
||||||
drinks, count = pricelist_controller.get_drinks(
|
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}")
|
logger.debug(f"GET drink {drinks}, {count}")
|
||||||
# return jsonify({"drinks": drinks, "count": count})
|
# return jsonify({"drinks": drinks, "count": count})
|
||||||
|
|
|
@ -131,12 +131,14 @@ def _create_public_drink(drink):
|
||||||
return None
|
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
|
count = None
|
||||||
if name:
|
if name:
|
||||||
query = Drink.query.filter(Drink.name.contains(name))
|
query = Drink.query.filter(Drink.name.contains(name))
|
||||||
else:
|
else:
|
||||||
query = Drink.query
|
query = Drink.query
|
||||||
|
if ingredient:
|
||||||
|
query = query.filter(Drink.cost_per_volume >= 0)
|
||||||
if search_name:
|
if search_name:
|
||||||
if search_key == "name":
|
if search_key == "name":
|
||||||
query = query.filter(Drink.name.contains(search_name))
|
query = query.filter(Drink.name.contains(search_name))
|
||||||
|
|
Loading…
Reference in New Issue