예제 #1
0
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_employee(body):  # noqa: E501
    """Add a new employee to the system. Role write:employees must be granted

     # noqa: E501

    :param body: Employee object that needs to be added to the system
    :type body: dict | bytes

    :rtype: Employee
    """
    if connexion.request.is_json:
        body = Employee.from_dict(connexion.request.get_json())  # noqa: E501
    # check email already exists
    found = dao.find_by_email(body.email)
    if found is not None:
        return ErrorApiResponse.EmployeeEmailExistError(body.email), 409
    # check for team number
    team = team_dao.get(body.team_id)
    if team is None:
        return ErrorApiResponse.TeamNotFoundError(id=body.team_id), 404
    # persist new employee
    orm = Employee_orm(
        full_name=body.full_name,
        position=body.position,
        specialization=body.specialization if body.specialization else '',
        team_id=body.team_id,
        expert=body.expert,
        email=body.email)
    try:
        dao.persist(orm)
        return find_employee_by_email(body.email)
    except Exception as ex:
        return ErrorApiResponse.InternalServerError(ex, type='employee'), 500
예제 #3
0
def get_team_by_id(teamId):  # noqa: E501
    """Find team by ID

    Returns a single team. # noqa: E501

    :param teamId: ID of team to return
    :type teamId: int

    :rtype: Team
    """
    found = dao.get(teamId)
    if found is None:
        return ErrorApiResponse.TeamNotFoundError(id=teamId), 404
    return to_team_dto(found)
예제 #4
0
def find_team_by_name(name):  # noqa: E501
    """Finds Team by name

     # noqa: E501

    :param name: Team name to find
    :type name: str

    :rtype: Team
    """
    found = dao.find_by_name(name)
    if found is None:
        return ErrorApiResponse.TeamNotFoundError(name=name), 404
    return to_team_dto(found)
예제 #5
0
def delete_team(teamId):  # noqa: E501
    """Deletes an team. Role write:teams must be granteds

     # noqa: E501

    :param teamId: Team id to delete
    :type teamId: int

    :rtype: ApiResponse
    """
    found = dao.get(teamId)
    if found is None:
        return ErrorApiResponse.TeamNotFoundError(id=teamId), 404
    try:
        dao.delete(found)
        return 'Successful operation', 204
    except Exception as ex:
        return ErrorApiResponse.InternalServerError(ex, type='team'), 500
def update_employee_by_id(employeeId, body):  # noqa: E501
    """Updates an employee in the system with form data. Role write:employees must be granted

     # noqa: E501

    :param employeeId: ID of empoyee to return
    :type employeeId: int
    :param body: Employee object that needs to be added to the system
    :type body: dict | bytes

    :rtype: Employee
    """
    found = dao.get(employeeId)
    if found is None:
        return ErrorApiResponse.EmployeeNotFoundError(id=employeeId), 404
    if connexion.request.is_json:
        body = Employee.from_dict(connexion.request.get_json())  # noqa: E501
    # check email already exists
    duplicate = dao.find_by_email(body.email)
    if duplicate is not None and duplicate.employee_id != body._employee_id:
        return ErrorApiResponse.EmployeeEmailExistError(body.email), 409
    # check for team number
    team = team_dao.get(body.team_id)
    if team is None:
        return ErrorApiResponse.TeamNotFoundError(id=body.team_id), 404
    found.full_name = body.full_name
    found.position = body.position
    found.specialization = body.specialization if body.specialization else ''
    found.team_id = body.team_id
    found.expert = body.expert
    found.email = body.email
    try:
        dao.persist(found)
        return get_employee_by_id(employeeId)
    except Exception as ex:
        return ErrorApiResponse.InternalServerError(ex, type='employee'), 500