Ejemplo n.º 1
0
    def update(self, product_to_update: Product) -> None:
        index_to_update = None

        for index, product in enumerate(self.__products):
            if product.id == product_to_update.id:
                index_to_update = index
                break

        if index_to_update is None:
            raise NotFound(f'product id: {product_to_update.id} not found')

        self.__products[index_to_update] = product_to_update
Ejemplo n.º 2
0
    def update(self, kit_to_update: Kit) -> None:
        index_to_update = None

        for index, kit in enumerate(self.__kits):
            if kit.id == kit_to_update.id:
                index_to_update = index
                break

        if index_to_update is None:
            raise NotFound(f'kit id: {kit_to_update.id} not found')

        self.__kits[index_to_update] = kit_to_update
Ejemplo n.º 3
0
    def remove(self, product_id: str) -> None:
        index_to_remove = None

        for index, product in enumerate(self.__products):
            if product.id == product_id:
                index_to_remove = index
                break

        if index_to_remove is None:
            raise NotFound(f'product id: {product_id} not found')

        self.__products.pop(index_to_remove)
Ejemplo n.º 4
0
    def remove(self, kit_id) -> None:
        index_to_remove = None

        for index, kid in enumerate(self.__kits):
            if kid.id == kit_id:
                index_to_remove = index
                break

        if index_to_remove is None:
            raise NotFound(f'kit id: {kit_id} not found')

        self.__kits.pop(index_to_remove)
Ejemplo n.º 5
0
 def get_by_sku(self, sku: str) -> Product:
     for product in self.__products:
         if product.sku == sku:
             return product
     raise NotFound(f'product sku: {sku} not found')
Ejemplo n.º 6
0
 def update(self, kit: Kit) -> None:
     kit_mongo = self.__create_mongo_kit_from_kit(kit)
     result = self.__collection.update_one({'_id': ObjectId(kit.id)},
                                           {'$set': kit_mongo})
     if result.matched_count < 1:
         raise NotFound(f'product id: {kit.id} not found')
Ejemplo n.º 7
0
 def remove(self, kit_id: str) -> None:
     result = self.__collection.delete_one({'_id': ObjectId(kit_id)})
     if result.deleted_count < 1:
         raise NotFound(f'kit id: {kit_id} not found')
Ejemplo n.º 8
0
 def get_by_id(self, product_id: str) -> Product:
     for product in self.__products:
         if product.id == product_id:
             return product
     raise NotFound(f'product id: {product_id} not found')
Ejemplo n.º 9
0
 def get_by_id(self, kit_id: str) -> Kit:
     mongo_product = self.__collection.find_one({'_id': ObjectId(kit_id)})
     if not mongo_product:
         raise NotFound(f'kit id: {kit_id} not found')
     return self.__create_kit_from_mongo(mongo_product)
Ejemplo n.º 10
0
 def update(self, product: Product) -> None:
     mongo_product = self.__create_mongo_product_from_product(product)
     result = self.__collection.update_one({'_id': ObjectId(product.id)},
                                           {'$set': mongo_product})
     if result.matched_count < 1:
         raise NotFound(f'product id: {product.id} not found')
Ejemplo n.º 11
0
 def get_by_sku(self, sku: str) -> Product:
     mongo_product = self.__collection.find_one({'sku': sku})
     if not mongo_product:
         raise NotFound(f'product sku: {sku} not found')
     return self.__create_product_from_mongo(mongo_product)
Ejemplo n.º 12
0
 def get_by_id(self, kit_id) -> Kit:
     for kit in self.__kits:
         if kit.id == kit_id:
             return kit
     raise NotFound(f'kit id: {kit_id} not found')