[pricelist] add, modify and delete for extra ingredients
This commit is contained in:
parent
642d95b2a5
commit
26e82f02d6
|
@ -202,3 +202,21 @@ def update_ingredient(identifier):
|
||||||
def delete_ingredient(identifier):
|
def delete_ingredient(identifier):
|
||||||
pricelist_controller.delete_ingredient(identifier)
|
pricelist_controller.delete_ingredient(identifier)
|
||||||
return "", NO_CONTENT
|
return "", NO_CONTENT
|
||||||
|
|
||||||
|
|
||||||
|
@pricelist_bp.route("/ingredients/extraIngredients", methods=["POST"])
|
||||||
|
def set_extra_ingredient():
|
||||||
|
data = request.get_json()
|
||||||
|
return jsonify(pricelist_controller.set_extra_ingredient(data))
|
||||||
|
|
||||||
|
|
||||||
|
@pricelist_bp.route("/ingredients/extraIngredients/<int:identifier>", methods=["PUT"])
|
||||||
|
def update_extra_ingredient(identifier):
|
||||||
|
data = request.get_json()
|
||||||
|
return jsonify(pricelist_controller.update_extra_ingredient(identifier, data))
|
||||||
|
|
||||||
|
|
||||||
|
@pricelist_bp.route("/ingredients/extraIngredients/<int:identifier>", methods=["DELETE"])
|
||||||
|
def delete_extra_ingredient(identifier):
|
||||||
|
pricelist_controller.delete_extra_ingredient(identifier)
|
||||||
|
return "", NO_CONTENT
|
||||||
|
|
|
@ -124,7 +124,7 @@ def set_drink(data):
|
||||||
allowedKeys = Drink().serialize().keys()
|
allowedKeys = Drink().serialize().keys()
|
||||||
if "id" in data:
|
if "id" in data:
|
||||||
data.pop("id")
|
data.pop("id")
|
||||||
values = {key: value for key, value in data.items() if key in allowedKeys}
|
values = {key: value if value != "" else None for key, value in data.items() if key in allowedKeys}
|
||||||
if "volumes" in values:
|
if "volumes" in values:
|
||||||
values.pop("volumes")
|
values.pop("volumes")
|
||||||
if "tags" in values:
|
if "tags" in values:
|
||||||
|
@ -341,3 +341,33 @@ def get_extra_ingredients():
|
||||||
|
|
||||||
def get_extra_ingredient(identifier):
|
def get_extra_ingredient(identifier):
|
||||||
return ExtraIngredient.query.get(identifier)
|
return ExtraIngredient.query.get(identifier)
|
||||||
|
|
||||||
|
|
||||||
|
def set_extra_ingredient(data):
|
||||||
|
allowedKeys = ExtraIngredient().serialize().keys()
|
||||||
|
if "id" in data:
|
||||||
|
data.pop("id")
|
||||||
|
values = {key: value for key, value in data.items() if key in allowedKeys}
|
||||||
|
extra_ingredient = ExtraIngredient(**values)
|
||||||
|
db.session.add(extra_ingredient)
|
||||||
|
db.session.commit()
|
||||||
|
return extra_ingredient
|
||||||
|
|
||||||
|
|
||||||
|
def update_extra_ingredient(identifier, data):
|
||||||
|
allowedKeys = ExtraIngredient().serialize().keys()
|
||||||
|
if "id" in data:
|
||||||
|
data.pop("id")
|
||||||
|
values = {key: value for key, value in data.items() if key in allowedKeys}
|
||||||
|
extra_ingredient = get_extra_ingredient(identifier)
|
||||||
|
if extra_ingredient:
|
||||||
|
for key, value in data.items:
|
||||||
|
setattr(extra_ingredient, key, value)
|
||||||
|
db.session.commit()
|
||||||
|
return extra_ingredient
|
||||||
|
|
||||||
|
|
||||||
|
def delete_extra_ingredient(identifier):
|
||||||
|
extra_ingredient = get_extra_ingredient(identifier)
|
||||||
|
db.session.delete(extra_ingredient)
|
||||||
|
db.session.commit()
|
||||||
|
|
Loading…
Reference in New Issue