def put(self, name): request_data = Item.parser.parse_args() item = ItemModel.find_by_name( name) #next(filter(lambda x: x['name'] == name, items),None) if item is None: item = ItemModel( name, ** request_data) #request_data['price'], request_data['store_id'] else: item.price = request_data['price'] item.save_db() return item.json()
def post(self, name): if ItemModel.find_by_name(name): return { 'Message': 'the item {} is already exist.'.format(name) }, 400 request_data = Item.parser.parse_args( ) #request.get_json(silent = True) item = ItemModel( name, **request_data) #request_data['price'], request_data['store_id'] try: item.save_db() except: return {"message": "An error occured inserting the item."}, 500 return item.json(), 201