Example #1
0
    def add_ingredient(user_id: int, recipe_id: int,
                       ingredient: Ingredient) -> Recipe:
        BaseService.is_object_exist(Recipe, recipe_id)
        BaseService.is_has_rights(Recipe, user_id, recipe_id)

        recipe = RecipeService.get(recipe_id)
        recipe.ingredients.add(ingredient)
        return recipe
Example #2
0
    def remove_from_recipe(user_id: int, recipe_id: int, tag: Tag) -> Tag:
        BaseService.is_object_exist(Recipe, recipe_id)
        BaseService.is_has_rights(Recipe, user_id, recipe_id)

        recipe = RecipeService.get(recipe_id)
        recipe.tags.remove(tag)
        TagService._decrease_tag_popularity(tag.pk)

        return tag
Example #3
0
    def add_to_recipe(user_id: int, recipe_id: int, tag: Tag) -> Tag:
        BaseService.is_object_exist(Recipe, recipe_id)
        BaseService.is_has_rights(Recipe, user_id, recipe_id)

        recipe = RecipeService.get(recipe_id)
        recipe.tags.add(tag)
        TagService._increase_tag_popularity(tag.pk)

        return tag
Example #4
0
    def add_recipe_step(user_id: int, recipe_id: int,
                        recipe_step: RecipeStep) -> Recipe:
        BaseService.is_object_exist(Recipe, recipe_id)
        BaseService.is_has_rights(Recipe, user_id, recipe_id)

        recipe = RecipeService.get(recipe_id)
        RecipeService._increase_steps_count(recipe)
        RecipeService._set_step_number(recipe, recipe_step)

        recipe.recipe_steps.add(recipe_step)
        return recipe