feature/pricelist #15

Merged
ferfissimo merged 11 commits from feature/pricelist into develop 2021-11-15 09:55:11 +00:00
2 changed files with 31 additions and 8 deletions
Showing only changes of commit 26a00ed6a6 - Show all commits

View File

@ -214,10 +214,21 @@ def get_drinks(identifier=None):
if identifier: if identifier:
result = pricelist_controller.get_drink(identifier, public=public) result = pricelist_controller.get_drink(identifier, public=public)
else:
result = pricelist_controller.get_drinks(public=public)
logger.debug(f"GET drink {result}")
return jsonify(result) return jsonify(result)
else:
limit = request.args.get("limit")
offset = request.args.get("offset")
try:
if limit is not None:
limit = int(limit)
if offset is not None:
offset = int(offset)
except ValueError:
raise BadRequest
drinks, count = pricelist_controller.get_drinks(public=public, limit=limit, offset=offset)
logger.debug(f"GET drink {drinks}, {count}")
# return jsonify({"drinks": drinks, "count": count})
return jsonify({"drinks": drinks, "count": count})
@PriceListPlugin.blueprint.route("/drinks/search/<string:name>", methods=["GET"]) @PriceListPlugin.blueprint.route("/drinks/search/<string:name>", methods=["GET"])

View File

@ -131,13 +131,22 @@ def _create_public_drink(drink):
return None return None
def get_drinks(name=None, public=False): def get_drinks(name=None, public=False, limit=None, offset=None):
count = None
if name: if name:
drinks = Drink.query.filter(Drink.name.contains(name)).all() query = Drink.query.filter(Drink.name.contains(name))
drinks = Drink.query.all() else:
query = Drink.query
if limit is not None:
count = query.count()
query = query.limit(limit)
if offset is not None:
query = query.offset(offset)
drinks = query.all()
if public: if public:
return [_create_public_drink(drink) for drink in drinks if _create_public_drink(drink)] return [_create_public_drink(drink) for drink in drinks if _create_public_drink(drink)], count
return drinks return drinks, count
def get_drink(identifier, public=False): def get_drink(identifier, public=False):
@ -209,6 +218,9 @@ def set_volumes(volumes):
def delete_drink(identifier): def delete_drink(identifier):
drink = get_drink(identifier) drink = get_drink(identifier)
if drink.uuid:
path = config["pricelist"]["path"]
delete_picture(f"{path}/{drink.uuid}")
db.session.delete(drink) db.session.delete(drink)
db.session.commit() db.session.commit()