Exemple #1
0
 def get(self, name):
     recipe = RecipeModel.find_by_name(name)
     if recipe:
         return recipe.json(name)
     return {
         'message': "There does not seem to be a recipe for that yet."
     }, 404
Exemple #2
0
    def put(self, name):
        data = Recipe.parser.parse_args()

        recipe = RecipeModel.find_by_name(name)

        if recipe:
            recipe.instructions = data['instructions']
        else:
            recipe = RecipeModel(name, data['instructions'])

        recipe.save_to_db()

        return recipe.json()
Exemple #3
0
    def post(self):
        data = self.parser.parse_args()
        if RecipeModel.find_by_name(data['name']):
            return {
                'message':
                "A recipe with name '{}' already exists.".format(data['name'])
            }, 400

        recipe = RecipeModel(**data)
        try:
            recipe.save_to_db()
        except:
            return {"message": "An error occurred creating the recipe."}, 500

        return recipe.json(), 201
Exemple #4
0
    def post(self, name):
        if RecipeModel.find_by_name(name):
            return {
                'message':
                "A recipe with name '{}' already exists.".format(name)
            }, 400

        data = Recipe.parser.parse_args()

        recipe = RecipeModel(name, data['instructions'], data['category_id'])

        try:
            recipe.save_to_db()
        except:
            return {"message": "An error occurred inserting the recipe."}, 500

        return recipe.json(), 201
Exemple #5
0
    def delete(self, name):
        recipe = RecipeModel.find_by_name(name)
        if recipe:
            recipe.delete_from_db()

        return {'message': 'Recipe deleted'}
Exemple #6
0
 def get(self, name):
     recipe = RecipeModel.find_by_name(name)
     if recipe:
         return recipe.json()
     return {'message': 'Recipe not found'}, 404