Exemplo n.º 1
0
    def put(self, name):
        """
        Create or Modify the existing item or new item
        """
        data = Item.parser.parse_args()

        item = ItemModel.find_item_name(name)
        updated_item = ItemModel(name, data['price'])

        if item is None:
            try:
                updated_item.insert()
            except:
                return {
                    "message": "An error occured while inserting the item"
                }, 500
        else:
            try:
                updated_item.update()
            except:
                return {
                    "message": "An error occured while updating the item"
                }, 500

        return updated_item.json()
Exemplo n.º 2
0
    def put(self, name):
        data = Item.parser.parse_args()
        item = ItemModel.find_by_name(name)
        updated_item = ItemModel(name, data['price'])

        if item is None:
            try:
                updated_item.insert()

            except:
                return {"message": "An error occurred inserting the item."}
        else:
            try:
                updated_item.update()
            except:
                raise
                return {"message": "An error occurred updating the item."}
        return updated_item
Exemplo n.º 3
0
    def put(self, name):
        data = Item.parser.parse_args()

        try:
            item = ItemModel.find_by_name(name)
        except:
            {'message': 'An error occurred attempting to retrieve the item from the database.'}, 500  # Internal Server Error
        updated_item = ItemModel(name, data['price'])

        if item is None:
            try:
                updated_item.insert()
            except:
                {'message': 'An error occurred attempting to insert the item into the database'}, 500  # Internal Server Error
        else:
            try:
                updated_item.update()
            except:
                {'message': 'An error occurred attempting to update the item in the database'}, 500  # Internal Server Error
        return updated_item.json()