def update_team_by_id(teamId, body): # noqa: E501 """Updates a team in the system with form data. Role write:teams must be granted # noqa: E501 :param teamId: ID of team to return :type teamId: int :param body: Team object that needs to be updated in the system :type body: dict | bytes :rtype: Team """ found = dao.get(teamId) if found is None: return ErrorApiResponse.TeamNotFoundError(id=teamId), 404 if connexion.request.is_json: body = Team.from_dict(connexion.request.get_json()) # noqa: E501 # check team already exists by name duplicate = dao.find_by_name(name=body.name) if duplicate is not None and duplicate.team_id != teamId: return ErrorApiResponse.TeamExistError(body.name), 409 found.name = body.name try: dao.persist(found) return get_team_by_id(teamId) except Exception as ex: return ErrorApiResponse.InternalServerError(ex, type='team'), 500
def add_team(body): # noqa: E501 """Add a new team to the system. Role write:teams must be granted # noqa: E501 :param body: Team object that needs to be added to the system :type body: dict | bytes :rtype: Team """ if connexion.request.is_json: body = Team.from_dict(connexion.request.get_json()) # noqa: E501 # check team already exists by name found = dao.find_by_name(body.name) if found is not None: return ErrorApiResponse.TeamExistError(body.name), 409 try: dao.persist(Team_orm(name=body.name)) return find_team_by_name(body.name) except Exception as ex: return ErrorApiResponse.InternalServerError(ex, type='team'), 500