def fill_to_create(purchase_list: PurchaseList, created_at: datetime,
                       created_by: User):
        if not purchase_list:
            return

        if not purchase_list.created_by:
            purchase_list.created_by = created_by
            purchase_list.created_at = created_at

        if not purchase_list.purchase_products:
            return

        for purchase_product in purchase_list.purchase_products:
            ProductService.fill_to_create(purchase_product.product, created_at,
                                          created_by)

        purchase_list.fill_total_estimated_value()
def delete_product(product_id: str, product_service: ProductService):
    product_service.delete_by_id(int(product_id))
    return {}, 200
def update_product(product_service: ProductService,
                   product_mapper: ProductMapper):
    product_dto = request.json
    product = product_service.update_from_dto(product_dto)
    return jsonify(product_mapper.to_dto(product))
def get_product(product_id: str, product_service: ProductService,
                product_mapper: ProductMapper):
    product = product_service.find_by_id(int(product_id))
    return jsonify(product_mapper.to_dto(product))
def get_all_products(product_service: ProductService,
                     product_mapper: ProductMapper):
    return jsonify(product_mapper.from_list_to_dto(product_service.find_all()))
Exemple #6
0
    def configure(self, binder: Binder):
        if not self.db:
            self.db = SQLAlchemy(self.app,
                                 session_options={"autoflush": False})

        dependencies = list()

        brand_dao = BrandDAO(self.db)
        dependencies.append(brand_dao)

        product_dao = ProductDAO(self.db)
        dependencies.append(product_dao)
        product_type_dao = ProductTypeDAO(self.db)
        dependencies.append(product_type_dao)
        purchase_dao = PurchaseDAO(self.db)
        dependencies.append(purchase_dao)
        purchase_list_dao = PurchaseListDAO(self.db)
        dependencies.append(purchase_list_dao)
        user_dao = UserDAO(self.db)
        dependencies.append(user_dao)
        user_group_dao = UserGroupDAO(self.db)
        dependencies.append(user_group_dao)

        user_group_mapper = UserGroupMapper(user_group_dao)
        dependencies.append(user_group_mapper)
        user_mapper = UserMapper(user_dao, user_group_mapper)
        dependencies.append(user_mapper)
        brand_mapper = BrandMapper(brand_dao, user_mapper)
        dependencies.append(brand_mapper)
        product_type_mapper = ProductTypeMapper(product_type_dao, user_mapper)
        dependencies.append(product_type_mapper)
        product_mapper = ProductMapper(product_dao, product_type_mapper,
                                       brand_mapper, user_mapper)
        dependencies.append(product_mapper)
        purchase_list_mapper = PurchaseListMapper(purchase_list_dao,
                                                  user_mapper, product_mapper)
        dependencies.append(purchase_list_mapper)
        purchase_mapper = PurchaseMapper(purchase_dao, user_mapper,
                                         product_mapper, purchase_list_mapper)
        dependencies.append(purchase_mapper)

        brand_service = BrandService(brand_dao, brand_mapper)
        dependencies.append(brand_service)
        product_type_service = ProductTypeService(product_type_dao,
                                                  product_type_mapper)
        dependencies.append(product_type_service)
        product_service = ProductService(product_dao, brand_service,
                                         product_type_service, product_mapper)
        dependencies.append(product_service)
        purchase_list_service = PurchaseListService(purchase_list_dao,
                                                    product_service,
                                                    purchase_list_mapper)
        dependencies.append(purchase_list_service)
        user_group_service = UserGroupService(user_group_dao)
        dependencies.append(user_group_service)
        user_service = UserService(user_dao, user_group_service, user_mapper)
        dependencies.append(user_service)
        purchase_service = PurchaseService(purchase_dao, purchase_list_service,
                                           product_service, purchase_mapper,
                                           product_type_mapper)
        dependencies.append(purchase_service)

        for instance in dependencies:
            binder.bind(type(instance), to=instance, scope=singleton)
 def setUp(self):
     self.service = ProductService(None, None, None, None)
class TestProductService(unittest.TestCase):
    def setUp(self):
        self.service = ProductService(None, None, None, None)

    def test_fill_create_without_dto(self):
        self.service.fill_to_create(None, datetime.utcnow(), None)