Ejemplo n.º 1
0
    def get(self, value):
        recipe = RecipeModel.find_by_value(value)
        
        if recipe:
            ingredients = RecipeModel.find_ingredients(recipe.id)
            return {"recipe": recipe.json(), "ingredients": ingredients}

        return {'message': 'Recipe not found'}, 404
Ejemplo n.º 2
0
 def post(self, value):
     user = UserModel.find_by_id(current_identity.id)
     user.current_order = RecipeModel.find_by_value(value).id
     user.save_to_db()
     return {
         "user": current_identity.id,
         "current_order": current_identity.current_order
     }
Ejemplo n.º 3
0
 def delete (self, value):
     recipe = RecipeModel.find_by_value(value)
     if recipe:
         mixings_to_delete = MixingModel.find_by_recipe(recipe.id)
         for row in iter(mixings_to_delete):
             row.delete_from_db()
         recipe.delete_from_db()
         return {'message': 'Recipe deleted'}
     return {'message': 'No such recipe'}
Ejemplo n.º 4
0
    def post(self, value):
        recipe_data = Recipe.recipe_parser.parse_args()
        portion_sum = 0

        if RecipeModel.find_by_value(value):
            return {'message': "Recipe '{}' already exist".format(value)}, 400

        recipe = RecipeModel(value, recipe_data['name'])
        for mixing in iter(recipe_data['ingredients_list']):
            portion_sum = portion_sum + mixing['portion']
        if portion_sum > 200:
            return {"meessage": "portion over limit"}
        
        try:
            recipe_id = recipe.save_to_db()
            for mixing in iter(recipe_data['ingredients_list']):
                mixing_model = MixingModel(mixing['ingredient_id'], recipe_id, mixing['portion'])
                mixing_model.save_to_db()
        except:
            return {'message': 'An error occured during saving to DB'}, 500
        
        return recipe.json(), 201