|
@@ -0,0 +1,81 @@
|
|
|
+from models.ingredient_model import ingredient_model
|
|
|
+from src.models.abstract_reference import abstract_reference
|
|
|
+from validation.validator import validator
|
|
|
+
|
|
|
+class receipt_model (abstract_reference):
|
|
|
+
|
|
|
+ __ingredients = list()
|
|
|
+
|
|
|
+
|
|
|
+ __steps = list()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ __vtor = validator()
|
|
|
+
|
|
|
+
|
|
|
+ def __init__(self, name, ingredients: list, steps: list):
|
|
|
+ self.__vtor.check_type(ingredients, list)
|
|
|
+ self.__vtor.check_collection_all(ingredients,
|
|
|
+ lambda item: self.__vtor.check_type(item, ingredient_model))
|
|
|
+
|
|
|
+ self.__vtor.check_type(steps, list)
|
|
|
+ self.__vtor.check_collection_all(steps,
|
|
|
+ lambda item: self.__vtor.check_type(item, str))
|
|
|
+ self.__vtor.check_collection_all(steps,
|
|
|
+ lambda item: self.__vtor.check_length_greater(item, 0))
|
|
|
+
|
|
|
+ self.__ingredients = ingredients
|
|
|
+ self.__steps = steps
|
|
|
+
|
|
|
+ super().__init__(name)
|
|
|
+
|
|
|
+
|
|
|
+ @property
|
|
|
+ def ingredients(self):
|
|
|
+ """Ингредиенты рецепта"""
|
|
|
+
|
|
|
+ return self.__ingredients
|
|
|
+
|
|
|
+ @ingredients.setter
|
|
|
+ def ingredients(self, ingredients: list):
|
|
|
+ """
|
|
|
+ Ингредиенты рецепта
|
|
|
+ Args:
|
|
|
+ ingredients (list): ингредиенты рецепта
|
|
|
+ Raises:
|
|
|
+ argument_exception: Несоответствие типа аргумента
|
|
|
+ argument_exception: Один из членов коллекции не прошел валидацию
|
|
|
+ """
|
|
|
+
|
|
|
+ self.__vtor.check_type(ingredients, list)
|
|
|
+ self.__vtor.check_collection_all(ingredients,
|
|
|
+ lambda item: self.__vtor.check_type(item, ingredient_model))
|
|
|
+
|
|
|
+ self.__ingredients = ingredients
|
|
|
+
|
|
|
+
|
|
|
+ @property
|
|
|
+ def steps(self):
|
|
|
+ """Шаги рецепта"""
|
|
|
+
|
|
|
+ return self.__steps
|
|
|
+
|
|
|
+ @steps.setter
|
|
|
+ def steps(self, steps: list):
|
|
|
+ """
|
|
|
+ Шаги рецепта
|
|
|
+ Args:
|
|
|
+ steps (list): шаги рецепта
|
|
|
+ Raises:
|
|
|
+ argument_exception: Несоответствие типа аргумента
|
|
|
+ argument_exception: Один из членов коллекции не прошел валидацию
|
|
|
+ """
|
|
|
+
|
|
|
+ self.__vtor.check_type(steps, list)
|
|
|
+ self.__vtor.check_collection_all(steps,
|
|
|
+ lambda item: self.__vtor.check_type(item, str))
|
|
|
+ self.__vtor.check_collection_all(steps,
|
|
|
+ lambda item: self.__vtor.check_length_greater(item, 0))
|
|
|
+
|
|
|
+ self.__steps = steps
|