def post(self, name): mall = MallModel.find_by_name(name) if mall is None: mall = MallModel(name) mall.save_to_db() else: return {'message': 'mall already exists.'}, 400
def delete(self, name): """Delete a mall by name.""" mall = MallModel.find_by_name(name) if mall: mall.delete_from_db() return {'message': "Mall with name '{}' deleted".format(name)} return {'message': 'mall not found.'}, 404
def delete(self, name): mall = MallModel.find_by_name(name) if mall: mall.delete_from_db() return {'message': 'mall deleted successfully'} else: return { 'message': 'mall with name {} does not exist'.format(name) }, 404
def delete(self, name): account = AccountModel.find_by_name(name) if account: mall = MallModel.find_by_id(account.id) if mall: mall.delete_from_db() account.delete_from_db() return {'message': "Account with name '{}' deleted".format(name)} return {'message': 'Account not found.'}, 404
def put(self, name): data = Mall.parser.parse_args() mall = MallModel.find_by_name(name) if mall: mall.address = data['address'] mall.account_id = data['account_id'] else: mall = MallModel(name, **data) mall.save_to_db() return mall.json()
def post(self, name): """Add mall by name.""" if MallModel.find_by_name(name): return { 'message': "An Mall with name '{}' already exists.".format(name) }, 400 data = Mall.parser.parse_args() mall = MallModel(name, **data) try: mall.save_to_db() except Exception as e: return {"message": "An error occurred inserting the mall."}, 500 return mall.json(), 201
def get(self): """Retvrieve malls using pagination""" from app import pagination return { 'malls': pagination.paginate(MallModel, MallModel.mall_fields()) }
def get(self, name): mall = MallModel.find_by_name(name) if mall: return mall.json() return {'message': 'Mall not found'}, 404
def get(self, name): mall = MallModel.find_by_name(name) if mall: return mall.json() else: return {'message': 'this mall {} does not exist'.format(name)}, 404
def account_filed(): """Resource fields for marshalling.""" return { 'name': fields.String, 'malls': fields.List(fields.Nested(MallModel.mall_fields())) }