def post(self, name): store = StoreModel.find_by_name(name) if store is None: store = StoreModel(name) store.save_to_db() return store.json() return {"message": "Store {} is already existed".format(name)}
def get(self, name): store = StoreModel.find_by_name(name) if store: return store.json() return { 'message': 'store not found' }, 404 #returned as a tuple and flask know which to assign to body and status code
def delete(self, name): store = StoreModel.find_by_name(name) if store: store.delete_from_db() return {"message": "Store deleted"}
def delete(self, name): store = StoreModel.find_by_name(name) if store: store.delete_from_db() return {'message': 'Store {} has been deleted'.format(name)} return {'message': 'store does not exist!'}
def delete(name): abort_if_store_doesnt_exist(name) deleted_store = StoreModel.find_by_name(name) if not ItemModel.query.filter_by(store_id=deleted_store.id).all(): deleted_store.delete_store() return {'message': "store '{}' was deleted".format(name)}, 201 else: return {'message': "store '{}' have to be empty".format(name)}, 201
def post(self, name): if StoreModel.find_by_name(name): return { "message": "Store {name} is already exists".format(name=name) }, 400 store = StoreModel(name) store.save_to_db() return store.json()
def post(self, name): if StoreModel.find_by_name(name): return {"massage": "store {} already exits.".format(name)}, 400 store = StoreModel(name) try: store.save() return store.json() except: return {"massage": "inserting store {} was not successful".format(name)}, 500
def delete(self, name): store = StoreModel.find_by_name(name) if store: try: store.delete() return {"massage": "deleting item {} was successful".format(name)}, 200 except: return {"massage": "deleting item {} was not successful".format(name)}, 500 else: return {"massage": "item {} doesn't exist in database"}
def post(self, name): if StoreModel.find_by_name(name): return {"message":"Store {} is already there.".format(name)}, 400 store = StoreModel(name) try: store.save_to_db() except: return {"message":"An internal error occured while creating store."}, 500 return store.json(), 201
def post (self,name): if StoreModel.find_by_name(name): return {'message' : "A store with that name'{}'alredy exists.".format(name)},400 store = StoreModel(name) try : store.save_to_db() except : return {'message' : 'An error occured while creating the store.'},500 return store.json(), 201
def post(self, name): if StoreModel.find_by_name(name): #if store already exists return {'message': 'Store {} already exists'.format(name)}, 400 store = StoreModel(name) #create store model try: store.save_to_db() except: return {'message': 'An error has occured'}, 500 return store.json(), 201
def put(name): if does_store_exist(name): changed_store = StoreModel.find_by_name(name) new_name = Store.parser.parse_args()['new_name'] abort_if_store_exist(new_name) changed_store.name = new_name db.session.commit() return {'changed_store': changed_store.json()}, 201 new_store = {'name': name} new_store = StoreModel(**new_store) new_store.add_store() return {'new_store': new_store.json()}, 201
def post(self, name): if StoreModel.find_by_name(name): return {'message': f'A store with name {name} already exists'}, 400 store = StoreModel(name) try: store.save_to_db() except: return { 'message': 'An error occured while creating the store' }, 500 return store.json(), 201
def post(self, name): if StoreModel.find_by_name(name): return { 'message': 'The item with the given name: {} already exists'.format(name) }, 400 store = StoreModel(name) try: store.save_to_db() except: return { "message": "AN error occured during Insertion" }, 500 # Internal Sever error return store.json(), 201 #status Code
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 store"}, 500 return store.json()
def post(self, name): store = StoreModel.find_by_name(name) try: if store: return { 'message': 'store with name {} exists'.format(name) }, 400 except: return {'message': 'error in saving store'}, 500 store = StoreModel(name) store.save_to_database() return store.json()
def post(self, name): if StoreModel.find_by_name(name): return { 'message': 'A Store with name {} is already there'.format(name) }, 400 store = StoreModel(name) try: store.save_to_db() except: return { 'message': 'An error occured while inserting item into database' }, 500 return store.json(), 201
def post(self, name): if StoreModel.find_by_name(name): return { 'message': "Store with this name '{}' already exists.".format(name) }, 400 store = StoreModel(name) try: store.save_to_db() # Save into database except 'Exception': return {"message": "Error occurred while inserting store"}, 500 return store.json(), 201
def get(self, name): store = StoreModel.find_by_name(name) if store: return store.json() return {"message":"Store not found"}, 404
def get(self, name): store = StoreModel.find_by_name(name) if store: return store.json() return {"message": "Store does not exists."}, 404
def delete(self, name): store = StoreModel.find_by_name(name) if store: store.delete_from_db() return {"message": "The store is deleted Successfully"}
def does_store_exist(name): if StoreModel.find_by_name(name) is not None: return True return False
def delete(self, name): store = StoreModel.find_by_name(name) if store: store.delete_from_database() return {'message': 'sotre deleted'} return {'message': 'store dont exist'}, 404
def delete(self, name): store = StoreModel.find_by_name(name) if store is None: return {"message": "{} not found".format(name)} store.delete() return {"message": "{} is deleted".format(name)}
def get(self, name): store = StoreModel.find_by_name(name) if store: return store.json() return {'message': 'Store didnt exits'}, 404
def get(name): abort_if_store_doesnt_exist(name) store = StoreModel.find_by_name(name) return {'store': store.json()}, 201
def get(self, name): store = StoreModel.find_by_name(name) if store: return store.json() return {"message": "Store Not Found...".format(name)}, 404
def delete(self, name): store = StoreModel.find_by_name(name) if store: store.delete() return {"message": "item deleted..."} return {"message": "No {} store".format(name)}
def delete(self, name): store = StoreModel.find_by_name(name) if store: store.delete_from_db() return {'message': 'Store has been deleted'}
def get(self, name): store = StoreModel.find_by_name(name) if store: return store.json() return {'message': 'Store not found'}, 404