def delete(self,_id): ingredient = IngredientModel.find_by_id(_id) if ingredient: IngredientModel.delete_from_db() return {'message' : 'Ingredient deleted'} return {'message': 'Ingredient not found'}, 404
def post(self): data = Ingredient.parser.parse_args() ingredient = IngredientModel(data['name'],data['amount'],data['measurement'],data['recipe_id']) try: ingredient.save_to_db() except: return {'message': 'Error occured when trying to save ingredient'}, 500 return ingredient.json(), 201
def find_ingredients(recipe_id): ingredients_dict = [] ingredients_query = MixingModel.find_by_recipe(recipe_id) for row in iter(ingredients_query): ingredient = IngredientModel.find_by_id(row.ingredient_id) ingredients_dict.append([dict(ingredient.json(), **(row.json()))]) return ingredients_dict
def __init__(self, name: str, *args, **kwargs) -> None: self.id = uuid.uuid4().__str__() self.name = name self.calories = kwargs.get('calories', None) self.instructions = kwargs.get('instructions', None) ingredients = kwargs.get('ingredients', list()) for ingredient in ingredients: self.ingredients.append(IngredientModel(ingredient['name'], ingredient['quantity'], self.id))
def get(self): uuid = request.args.get('uuid') if not uuid: return {'message': 'missing uuid parameter'}, 400 recipe = IngredientModel.findby_id(uuid) if recipe: return ingredient_schema.dump(recipe), 200 return {'message': 'Ingredient not found', 'description': uuid}, 404
def put(self,_id): data = Ingredient.parser.parse_args() ingredient = IngredientModel(data['name'],data['amount'],data['measurement'],data['store_id']) if IngredientModel.find_by_id(_id): ingredient.id = _id ingredient.save_to_db() return ingredient.json()
def get(self, name): """ To get the ingredient details :param name: Name of the ingredient. :return: Returns the details of ingredients with name and amount. """ ingredient = IngredientModel.find_by_name(name) if ingredient: return ingredient.json(), 200 return {"message": "Ingredient {} not found.".format(name)}, 404
def put(self, name): data = Ingredient.parser.parse_args() ingredient = IngredientModel.find_by_name(name) if not ingredient: ingredient = IngredientModel(name, **data) else: ingredient.price = data['amount'] ingredient.save_to_db() return ingredient.json(), 201
def post(self, value): if IngredientModel.find_by_value(value): return {'message': "Item '{}' already exists".format(value)}, 400 data = Ingredient.parser.parse_args() item = IngredientModel(value, **data) item.save_to_db() return item.json(), 201
def post(self, name): if IngredientModel.find_by_name(name): return {'message': 'An ingredient with name {} already exist'.format(name)}, 400 # data = request.get_json(silent=True) data = Ingredient.parser.parse_args() ingredient = IngredientModel(name, **data) try: ingredient.save_to_db() except: return {"message": "Error in inserting ingredient {}".format(name)}, 500 return ingredient.json(), 201
def get(self, value): def find_possible_drinks(ingredient_id): possible_drinks_dict = [] possible_drinks = MixingModel.find_by_ingredient(ingredient_id) for row in iter(possible_drinks): drink = RecipeModel.find_by_id(row.recipe_id) possible_drinks_dict.append(drink.json()) return possible_drinks_dict ingredient = IngredientModel.find_by_value(value) if ingredient: possible_drinks_dict = find_possible_drinks(ingredient.id) return { "ingredient": ingredient.json(), "possible drinks": possible_drinks_dict } return {"message": 'Ingredient not found'}, 404
def post(self, recipe_id, ingredient_id): data = RecipeIngredient.parser.parse_args() if not IngredientModel.find_by_id(ingredient_id): return {'message': "That ingredient does not exist"}, 404 if not RecipeModel.find_by_id(recipe_id): return {'message': "That recipe does not exist"}, 404 if RecipeIngredientModel.find_by_recipe_ingredient( recipe_id, ingredient_id): return {'message': "That recipe already contains that ingredient."} ri = RecipeIngredientModel(data['amount'], recipe_id, ingredient_id) print(ri.json()) try: ri.save_to_db() except: return { "message": "An error occurred inserting the recipe ingredient." }, 500 return ri.json(), 201
def post(self): data = self.parser.parse_args() if IngredientModel.find_by_name_measurement(data['name'], data['measurement']): return { 'message': 'An ingredient with that name and measurement type already exists' } ingredient = IngredientModel(**data) try: ingredient.save_to_db() except: return { 'message': 'An error occurred while inserting the ingredient' }, 500 return ingredient.json(), 201
def put(self, value): print(current_identity.username) data = Ingredient.parser.parse_args() pump_check = IngredientModel.find_by_pump(data['pump']) if pump_check: return { 'message': 'Pump already in use in:', 'ingredient': pump_check.name } ingredient = IngredientModel.find_by_value(value) if ingredient: ingredient.name = data['name'] ingredient.amount = data['amount'] ingredient.voltage = data['voltage'] ingredient.pump = data['pump'] else: ingredient = IngredientModel(value, **data) ingredient.save_to_db() return ingredient.json()
def get(self): return { 'recipes': list(map(lambda x: x.json(), IngredientModel.get_all_pumps())) }
def get(self,recipe_id): return {'items': [i.json() for i in IngredientModel.find_by_recipe(recipe_id)]}
def delete(self, name): ingredient = IngredientModel.find_by_name(name) if ingredient: ingredient.delete_from_db() return {"message": "Ingredient {} deleted".format(name)} return {"message": "Ingredient {} does not exist.".format(name)}
def get(self): ingredients = [x.json() for x in IngredientModel.find_all()] return {'ingredients': ingredients}, 200
def delete(self, value): ingredient = IngredientModel.find_by_value(value) if ingredient: ingredient.delete_from_db() return {"message": "Item deleted"} return {"message": "No such item"}
def get(self,_id): ingredient = IngredientModel.find_by_id(_id) if ingredient: return ingredient.json() return {'message': 'Ingredient not found'}, 404