| 1234567891011121314151617181920212223242526272829303132333435363738 |
- from .product import product
- from .product import product_factory
- class product_builder:
- def __init__(self, target: product | None = None) -> None:
- self.__target = target
- if self.__target is None:
- self.__target = product()
- def modify(self, target: dict) -> object:
- factory = product_factory(target)
- if "name" in target:
- factory.name = target["name"]
- if "description" in target:
- factory.description = target["description"]
- if "author" in target:
- factory.author = target["author"]
- if "image" in target:
- factory.image = target["image"]
- if "stock_count" in target:
- factory.stock_count = target["stock_count"]
- if "barcode" in target:
- factory.barcode = target["barcode"]
- self.__target = factory.result
- return self
- @property
- def result(self) -> product:
- return self.__target
|