def post(self): data = AccountPost.parser.parse_args() account = AccountModel(**data) try: account.save_to_db() except Exception as e: return {"message": "An error occurred creating the account."}, 500 return account.json(), 201
def put(self, name): data = Account.parser.parse_args() account = AccountModel.find_by_name(name) if account is None: account = AccountModel(name, **data) else: account.is_active = data['is_active'] account.save_to_db() return account.json()
def post(self, name): if AccountModel.find_by_name(name): return { "message": "An item with name '{}' already exists." .format(name)}, 400 data = Account.parser.parse_args() account = AccountModel(name, **data) try: account.save_to_db() except: return {"message": "An error occurred adding the account."}, 500 return account.json(), 201