def post(cls): data = Item.parser.parse_args() if ItemModel.find_by_name(data['item_name']): return {'message': "item {} already exists.".format(data['item_name'])} data = Item.parser.parse_args() item = ItemModel(data['item_name'], data['price'], insert_timestamp()) item.created_timestamp = insert_timestamp() try: item.save_to_db() except: return {"message": "An error occurred inserting the Item."}, 500 return item.json(), 201
def put(cls): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'Admin privilege required.'}, 401 data = Item.parser.parse_args() item = ItemModel.find_by_name(data['item_name']) if item is None: item = ItemModel(data['item_name'], data['price'], insert_timestamp()) item.created_timestamp = insert_timestamp() else: item.price = data['price'] item.modify_timestamp = insert_timestamp() item.save_to_db() return item.json()