def put(self, name): payload = Item.parser.parse_args() item = ItemModel.find_item_by_name(name) if item is None: item = ItemModel(name, payload["price"], payload['store_id']) else: item.price = payload['price'] item.store_is = payload['store_id'] item.save_to_db() return item.json()
def put(self, name): data = Item.parser.parse_args() item = ItemModel.find_by_name(name) if item is None: item = ItemModel(name, **data) else: item.price = data["price"] item.store_id = data["store_id"] item.save_to_db() return item.json()
def put(self, name): data = Item.parser.parse_args() item = ItemModel.find_by_name(name) if not item: item = ItemModel(name, **data) else: item.price = data['price'] item.save_to_db() return item.json()
def put(self, name): data = Item.parser.parse_args() item = ItemModel.find_by_name(name) if item is None: item = ItemModel(name, data['price'], data['store_id']) else: item.price = data['price'] item.save_to_db() return item.json()
def put(self, name): data = Item.parser.parse_args() itemModel = ItemModel.find_by_ItemName(name) if itemModel is None: itemModel = ItemModel(name, data['price']) else: itemModel.price = data['price'] itemModel.save_to_database() return itemModel.json()
def put(self, item_name): # data = request.get_json() # replaced by parser code above data = Item.parser.parse_args() item = ItemModel.find_by_name(item_name) if item is None: item = ItemModel(item_name, data["price"], data["store_id"]) else: item.price = data["price"] item.save_to_db() return item.json()
def put(self, name): data = Item.parser.parse_args() item = ItemModel.find_by_name(name) if item is None: item = ItemModel(name, **data) else: item.price = data['price'] try: item.save_to_db() return item.json(), 201 except: return {"message": "An error iccorred while updateing item"}, 500
def put(self, name): data = Item.request_parser.parse_args() item = ItemModel.find_by_name(name) if item is None: item = ItemModel(name, data['price'], data['store_id']) else: item.price = data['price'] try: item.save_to_db() except: return {'message': 'Internal server error while updating'}, 500 return item.json()
def put(self, name): data = Item.parser.parse_args() # Once again, print something not in the args to verify everything works # item = next(filter(lambda x: x['name'] == name, items), None) item = ItemModel.find_by_name(name) if item is None: item = ItemModel(name, data['price'], data['store_id']) else: item.price = data['price'] # item.store_id = data['store_id'] item.save_to_db() return item.json()
def put(self, name): # data=request.get_json() data = self.parser.parse_args() item = ItemModel.find_by_name(name) # updated_item=ItemModel(name,data["price"]) if item is None: # item=ItemModel(name,data['price'],data['store_id']) item = ItemModel(name, **data) else: item.price = data['price'] item.save_to_db() return item.json()
def put(self, name): item = ItemModel.find_by_name(name) data = Item.parser.parse_args() if item is None: #same as below// item = ItemModel(name, data['price'], data['store_id']) item = ItemModel(name, **data) else: item.price = data['price'] item.store_id = data['store_id'] item.save_to_db() return item.json(), 201
def put(self, name): request_data = Item.parser.parse_args() put_item = ItemModel.find_by_name(name) # Check if item is in db try: if put_item is None: put_item = ItemModel( name, request_data['price']) else: put_item.price = request_data['price'] except: return {"mesage": "An error occured updating the item"}, 500 put_item.save_to_db() return{'message': "An item with name '{}' updated successfully.".format(name)}, 201
def put(self, name): data = Item.parser.parse_args() item = ItemModel.find_by_name(name) # updated_item = ItemModel(name, data['price']) try: if item is None: item = ItemModel(name, data['price'], data['store_id']) # updated_item.insert() else: # updated_item.update() item.price = data['price'] item.insert_in_db() except Exception as e: return {'message': 'Error'}, 500 # return updated_item.json() return item.json()
def put(self, name): data = Item.parser.parse_args() item = ItemModel.find_by_name(name) if item is None: try: item = ItemModel(name, **data) except: return {"message": "An error occurred inserting the item."} else: try: item.price = data['price'] # should I add store id? except: return {"message": "An error occurred updating the item."} item.save_to_db() return item.json()
def put(self, name): # parser = reqparse.RequestParser() # parser.add_argument('price', # type=float, # required=True, # help="This fies cannot be left blanked" # # ) #data = request.get_json() data = Item.parser.parse_args() #item = next(filter(lambda x:x['name'] == name,items), None) item = ItemModel.find_by_name(name) #updated_item = ItemModel(name, data['price']) if item is None: item = ItemModel(name, data['price'], data['store_id']) else: item.price = data['price'] item.save_to_db() return item.json()