Example #1
0
    def delete_by_id(self, product_id: int):
        product = self.product_dao.find_by_id(product_id, AuthenticationContext.get_current_user())

        if not product:
            raise ObjectNotFoundException(ErrorCode.PRODUCT_TO_DELETE_NOT_FOUND, Product.__name__, {"id": product_id})

        self.product_dao.delete(product)
Example #2
0
    def delete_by_id(self, brand_id: int):
        brand = self.find_by_id(brand_id)

        if not brand:
            raise ObjectNotFoundException(ErrorCode.BRAND_TO_DELETE_NOT_FOUND, Brand.__name__, {"id": brand_id})

        self.brand_dao.delete(brand)
    def delete_by_id(self, purchase_list_id: int):
        purchase_list = self.find_by_id(purchase_list_id)

        if not purchase_list:
            raise ObjectNotFoundException(
                ErrorCode.PURCHASE_LIST_TO_DELETE_NOT_FOUND,
                PurchaseList.__name__, {"id": purchase_list_id})

        self.purchase_list_dao.delete(purchase_list)
    def delete_by_id(self, product_type_id: int):
        product_type = self.find_by_id(product_type_id)

        if not product_type:
            raise ObjectNotFoundException(
                ErrorCode.PRODUCT_TYPE_TO_DELETE_NOT_FOUND,
                ProductType.__name__, {"id": product_type_id})

        self.product_type_dao.delete(product_type)
Example #5
0
    def update_from_dto(self, dto: dict):
        self.mapper.validate_dto_to_update(dto)

        brand = self.brand_dao.find_by_id(dto.get("id"), AuthenticationContext.get_current_user())

        if not brand:
            raise ObjectNotFoundException(ErrorCode.BRAND_TO_UPDATE_NOT_FOUND,  Brand.__name__, {"id": dto.get("id")})

        brand = self.mapper.to_object(dto)

        self.brand_dao.update(brand)

        return brand
Example #6
0
    def update_from_dto(self, dto: dict):
        self.mapper.validate_dto_to_update(dto)

        product = self.product_dao.find_by_id(dto.get("id"), AuthenticationContext.get_current_user())

        if not product:
            raise ObjectNotFoundException(ErrorCode.PRODUCT_TO_UPDATE_NOT_FOUND,
                                          Product.__name__, {"id": dto.get("id")})

        product = self.mapper.to_object(dto)
        ProductService.fill_to_create(product, datetime.utcnow(), AuthenticationContext.get_current_user())

        self.product_dao.update(product)

        return product
    def update_from_dto(self, dto: dict):
        self.mapper.validate_dto_to_update(dto)

        purchase_list = self.find_by_id(dto.get("id"))

        if not purchase_list:
            raise ObjectNotFoundException(
                ErrorCode.PURCHASE_LIST_TO_UPDATE_NOT_FOUND,
                PurchaseList.__name__, {"id": dto.get("id")})

        self.mapper.to_object(dto)

        PurchaseListService.fill_to_create(
            purchase_list, datetime.utcnow(),
            AuthenticationContext.get_current_user())

        self.purchase_list_dao.update(purchase_list)

        return purchase_list
Example #8
0
    def update_from_dto(self, dto: dict):
        self.mapper.validate_dto_to_update(dto)

        user = self.find_by_id(dto.get("id"))

        if not user:
            raise ObjectNotFoundException(ErrorCode.USER_TO_UPDATE_NOT_FOUND,
                                          User.__name__, {"id": dto.get("id")})

        if user != AuthenticationContext.get_current_user():
            raise PermissionException(ErrorCode.UPDATE_USER_PERMISSION,
                                      User.__name__, Actions.UPDATE)

        user = self.mapper.to_object(dto)

        if dto.get("password"):
            user.password = PasswordEncryption.encrypt_password(
                dto.get("password"))

        self.user_dao.update(user, commit=True)

        return user