Beispiel #1
0
def delete_alt_ingredient(ingredient_id, alt_ingredient_id):
    alt_ingredient = models.IngredientAlternative.query \
        .filter(models.IngredientAlternative.ingredient_id == ingredient_id,
                models.IngredientAlternative.alt_ingredient_id == alt_ingredient_id).one()
    db.session.delete(alt_ingredient)
    db.session.commit()

    ingredients_schema = models.IngredientSchema(
        many=True, exclude=['alternatives', 'ingredient_alternative'])
    ingredient = models.Ingredient.query.filter(
        models.Ingredient.id == ingredient_id).one()
    alt_ingredients = ingredient.alternatives.all()
    return ingredients_schema.dump(alt_ingredients).data
Beispiel #2
0
def edit_ingredient(id, name=None, description=None, nutrition=None, is_allergen=None, type=None):
    ingredient = models.Ingredient.query.filter(models.Ingredient.id == id).one()
    ingredient.name = name or ingredient.name
    ingredient.description = description or ingredient.description
    ingredient.nutrition = description or ingredient.nutrition
    ingredient.is_allergen = is_allergen or ingredient.is_allergen
    ingredient.type = type or ingredient.type

    db.session.commit()

    ingredient_schema = models.IngredientSchema()
    ingredient_tuple = collections.namedtuple('IngredientData', ['id', 'data'])
    result = ingredient_tuple(id=ingredient.id, data=ingredient_schema.dump(ingredient).data)
    return result
Beispiel #3
0
def get_ingredients():
    ingredients_schema = models.IngredientSchema(many=True)
    ingredients = models.Ingredient.query.all()
    return ingredients_schema.dump(ingredients).data
Beispiel #4
0
def get_ingredient(_id):
    ingredient_schema = models.IngredientSchema()
    ingredient = models.Ingredient.query.filter(models.Ingredient.id == _id).one()
    return ingredient_schema.dump(ingredient).data
Beispiel #5
0
def get_alt_ingredients(_id):
    ingredients_schema = models.IngredientSchema(
        many=True, exclude=['alternatives', 'ingredient_alternative'])
    ingredient = models.Ingredient.query.filter(
        models.Ingredient.id == _id).one()
    return ingredients_schema.dump(ingredient.alternatives.all()).data