def put(self, name): data = Store.parser.parse_args() store = StoreModel.find_by_name(name) if store is None: new_item = StoreModel(None, name, data['price'], data['store_id']) try: new_item.save_to_db() new_item = StoreModel.find_by_name(name) except: return { 'message': 'An error occurred inserting the store' }, 500 # Internal Server Error return new_item.json(), 201 else: store.price = data['price'] store.store_id = data['store_id'] try: store.save_to_db() store = StoreModel.find_by_name(name) except: return { 'message': 'An error occurred updating the store' }, 500 # Internal Server Error return {'message': "Updated successfully", 'store': store.json()}
def post(self, name): if StoreModel.find_by_name(name): return {"message": "Store already exists."}, 400 store = StoreModel(name) try: store.save_to_db() except: return {"message": "An arror occurd during creating store"}, 500 return store.json, 201
def post(self, name): if StoreModel.find_by_name(name): return {"message": "Store {} already exists".format(name)}, 400 store = StoreModel(name) try: store.save_to_db() except: return {"message": "Error occured creating db"}, 500 return store.json(), 201
def post(self, name): if StoreModel.find_by_name(name): return {'message': "A store with name '{}' already exists".format(name)}, 400 store = StoreModel(name) try: store.save_to_db() except: return {'message': "An error occurred while creating the store"}, 500 return store.json()
def post(self, name): if StoreModel.find_by_name(name): return {'message': f"A store with name {name} already exist"}, 400 store = StoreModel(name) try: store.save_to_db() except: return {'message': 'Error while parsing via server'}, 500 return store.json(), 201
def post(self, name): if StoreModel.find_by_name(name): return { 'Message': "The store '{}' is already exist".format(name) }, 400 new_store = StoreModel(None, name) try: new_store.save_to_db() new_store = StoreModel.find_by_name(name) except: return { 'message': 'An error occurred inserting the item' }, 500 # Internal Server Error return new_store.json(), 201
def post(name): if StoreModel.find_by_name(name): return { 'message': "A store with name '{}' already exists.".format(name) }, 400 store = StoreModel(name) try: store.save_to_db() except ConnectionError: return {"message": "An error occurred creating the store."}, 500 return store.json(), 201
def post(self, name): if StoreModel.find_by_name(name): return { 'message': "A store with name '{}' already exists".format(name) }, 400 # 400 => BAD REQUEST # Store.parser.parse_args() store = StoreModel(name) try: store.save_to_db() except: return {'message': 'An error ocurred inserting item.'}, 500 return store.json(), 201 # 201 => CREATED