示例#1
0
 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
示例#2
0
 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()
示例#3
0
 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'}
示例#4
0
 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