Selaa lähdekoodia

Moved recipe_model initialization in a factory

Vsevolod Levitan 1 vuosi sitten
vanhempi
commit
58d0abc2e9
1 muutettua tiedostoa jossa 20 lisäystä ja 14 poistoa
  1. 20 14
      src/models/recipe_model.py

+ 20 - 14
src/models/recipe_model.py

@@ -14,23 +14,29 @@ class recipe_model (abstract_reference):
     __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
-
+    def __init__(self, name):
         super().__init__(name)
 
     
+    @staticmethod
+    def create(name, ingredients:list=None, steps:list=None):
+        """
+            Фабричный метод для создания рецепта
+        Args:
+            ingredients?: список ингредиентов
+            steps?: список шагов по приготовлению
+        Returns:
+            recipe_model: Созданный рецепт
+        """
+
+        recipe = recipe_model(name)
+        
+        recipe.ingredients = ingredients if ingredients is not None else list()
+        recipe.steps = steps if steps is not None else list()
+
+        return recipe
+
+
     @property
     def ingredients(self):
         """Ингредиенты рецепта"""