예제 #1
0
    def default_product_with(self, name, gtin, price, sub_category_id):
        sub_category = self.__sub_category_repo.get_by_id(sub_category_id)
        if not sub_category:
            raise ProductRequiresSubCategoryException(sub_category_id)

        # if not gtin_should_be_unique_validation(self.__product_repo, gtin):
        #     raise ProductWithDuplicatedGtinException(gtin)

        product = Product(name=name,
                          gtin=gtin,
                          price=price,
                          sub_category=sub_category)

        guard = ProductGuard()
        if not guard.check(product):
            raise ProductException(guard.get_issues())

        return product
예제 #2
0
    def default_product_to_update(self, _id, name, gtin, price,
                                  sub_category_id):
        sub_category = self.__sub_category_repo.get_by_id(sub_category_id)
        if not sub_category:
            raise ProductRequiresSubCategoryException(sub_category_id)

        product = self.__product_repo.get_by_id(_id)
        if not product:
            raise ProductNotFoundException(_id)

        if gtin != product.gtin:
            if not gtin_should_be_unique_validation(self.__product_repo, gtin):
                raise ProductWithDuplicatedGtinException(gtin)

        product.name = name
        product.gtin = gtin
        product.price = price
        product.sub_category = sub_category

        guard = ProductGuard()
        if not guard.check(product):
            raise ProductException(guard.get_issues())

        return product