def put(self, name): request_data = Items.parser.parse_args() item = ItemsModel.find_items_by_name(name) if item: try: item.price = request_data['price'] item.save_to_db() except: return {'message': 'An error occurred updateing an item'}, 500 return {'message': 'Record Updated'} else: return {'Message': 'No Record Found in DataBase To update'}, 400
def post(self, name): if ItemsModel.find_items_by_name(name): return { 'Message': f'The item with name {name} is already exisit' }, 400 request_data = Items.parser.parse_args() items_list = ItemsModel(name, **request_data) try: items_list.save_to_db() except: return {'message': 'An error occurred inserting an item'}, 500 return items_list.json()
def delete(self, name): item = ItemsModel.find_items_by_name(name) if item: item.delete() return {'Message': f'Item {name} is Deleted'} return {'Message': f'The Item {name} is not in the database'}
def get(self, name): items = ItemsModel.find_items_by_name(name) if items: return items.json() return {'message': 'No Record Found in Data Base'}, 400