def get(self, name: str): store = StoreModel.find_by_storename(name) if store: return store.json() return {'message': f"Store with name '{name}' not found."}, 404
def delete(self, name: str): store = StoreModel.find_by_storename(name) if store: store.delete_store() return {'message': 'Store Deleted.'} return {'message': 'Store not found.'}, 404
def post(self, name): if StoreModel.find_by_storename(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 creating the store."}, 500 return store.json(), 201
def post(self, name: str): store = StoreModel.find_by_storename(name) if store: return { 'message': f"A store with the name {name} already exists!" }, 400 store = StoreModel(name) try: store.save_store_to_db() except: return { 'message': f"An error occurred whilst inserting the store 😞" }, 500 return store.json(), 201
def put(self, name: str): data = Store.parser.parse_args() store = StoreModel.find_by_storename(name) if store: try: store.name = data['name'] store.save_store_to_db() except: return { 'message': f"An error occurred updating this store" }, 500 else: try: store = StoreModel(name) store.save_store_to_db() except: return { 'message': f"An error occurred inserting this item" }, 500 return store.json(), 201
def get(self, name): store = StoreModel.find_by_storename(name) if store: return store.json() return {'message': 'Store not found'}, 404
def delete(self, name): store = StoreModel.find_by_storename(name) if store: store.delete_from_db() return {'message': 'Store deleted'}