コード例 #1
0
    def get_recipe(self, uuid):
        res = self.find_one({'recipe_uuid': uuid})

        if not res:
            return False

        c_recipe = Recipe()
        c_recipe.from_mongo(res)
        return c_recipe
コード例 #2
0
    def get_recipes(self):
        recipes = self.find_all()

        r_recipes = []
        for l_recipe in recipes:
            new_recipe = Recipe()
            new_recipe.from_mongo(l_recipe)
            r_recipes.append(new_recipe.json())

        return r_recipes
コード例 #3
0
    def update_recipe(self, uuid: str, title: str, prep_time: int, ingredients: list, preperation: list):
        res = self.find_one({'recipe_uuid': uuid})

        if not res:
            return return_json(success=False, error="recipe not found")

        c_recipe = Recipe()

        c_recipe.from_mongo(res)

        c_recipe.title = title
        c_recipe.prep_time = prep_time
        c_recipe.ingredients = ingredients

        for item in c_recipe.ingredients:
            item.capitalize()

        c_recipe.preperation = preperation

        for item in c_recipe.preperation:
            item.capitalize()

        self.update_one({'recipe_uuid': uuid}, {"$set": c_recipe.json()})