def post(self, name): if GroupModel.find_by_name(name): return {'message': "A group with name '{}' already exists.".format(name)}, 400 group = GroupModel(name) try: group.save_to_db() except Exception as e: return {"message": f"An error occurred: {e}"}, 500 return group.json(), 201
def post(self): data = Group.parser.parse_args() if GroupModel.find_by_name(data['name']): return {'message': 'Group with that name already exists.'}, 400 group = GroupModel(data['name'], data['description']) group.save_to_db() return group.json(), 201
def post(self, name=None): data = json.loads(request.data) name = data.get("name", name) if GroupModel.find_by_name(name): return { 'error': "A group with name '{}' already exists.".format(name) }, 400 group = GroupModel(**data) try: group.save_to_db() except: return {"error": "An error occurred creating the group."}, 500 return group.json(), 201