예제 #1
0
    def post(self):
        recipe = RecipeModel(**request.get_json())
        if RecipeModel.findby_name(recipe.name):
            return {
                'message':
                "Recipe with this name '{}' already exists".format(recipe.name)
            }, 400

        recipe.saveto_db()
        return {'recipe': recipe_schema.dump(recipe)}, 201
예제 #2
0
    def put(self):
        recipe_data = recipe_schema.load(request.get_json())

        recipe = RecipeModel.findby_name(recipe_data.name)
        if not recipe:
            return {
                'message': "Recipe not found",
                'description': recipe_data.name
            }, 404

        if recipe_data.name: recipe.name = recipe_data.name
        if recipe_data.calories: recipe.calories = recipe_data.calories
        if recipe_data.instructions:
            recipe.instructions = recipe_data.instructions

        recipe.saveto_db()
        return {'recipe': recipe_schema.dump(recipe)}, 200