def put(self, recipe_id): """ PUT Recipe API """ data = api.payload recipe = RecipeModel.query.get(recipe_id) _ = data.pop('id', None) user_id = current_identity.id if not recipe: recipe = RecipeModel.add(data, user_id=user_id) else: recipe.update(data, user_id=user_id) return recipe.json(), 201
def post(self): """ Recipe Post API. """ data = api.payload name = data.get('name') recipe_obj = None user_id = current_identity.id try: recipe_obj = RecipeModel.add(data, user_id=user_id) except Exception as exc: print(exc) return { "ok": False, "message": f"An error occurred while creating recipe {name}" }, 500 return recipe_obj.json(), 201