[pricelist] add serverside pagination and filter for receipts

This commit is contained in:
Tim Gröger 2021-11-13 15:44:06 +01:00
parent 526433afba
commit e4b937991b
2 changed files with 9 additions and 1 deletions

View File

@ -221,6 +221,7 @@ def get_drinks(identifier=None):
search_name = request.args.get("search_name")
search_key = request.args.get("search_key")
ingredient = request.args.get("ingredient", type=bool)
receipt = request.args.get("receipt", type=bool)
try:
if limit is not None:
limit = int(limit)
@ -228,6 +229,8 @@ def get_drinks(identifier=None):
offset = int(offset)
if ingredient is not None:
ingredient = bool(ingredient)
if receipt is not None:
receipt = bool(receipt)
except ValueError:
raise BadRequest
drinks, count = pricelist_controller.get_drinks(
@ -237,6 +240,7 @@ def get_drinks(identifier=None):
search_name=search_name,
search_key=search_key,
ingredient=ingredient,
receipt=receipt,
)
logger.debug(f"GET drink {drinks}, {count}")
# return jsonify({"drinks": drinks, "count": count})

View File

@ -131,7 +131,9 @@ def _create_public_drink(drink):
return None
def get_drinks(name=None, public=False, limit=None, offset=None, search_name=None, search_key=None, ingredient=False):
def get_drinks(
name=None, public=False, limit=None, offset=None, search_name=None, search_key=None, ingredient=False, receipt=None
):
count = None
if name:
query = Drink.query.filter(Drink.name.contains(name))
@ -139,6 +141,8 @@ def get_drinks(name=None, public=False, limit=None, offset=None, search_name=Non
query = Drink.query
if ingredient:
query = query.filter(Drink.cost_per_volume >= 0)
if receipt:
query = query.filter(Drink.volumes.any(DrinkPriceVolume.ingredients != None))
if search_name:
if search_key == "name":
query = query.filter(Drink.name.contains(search_name))