Exemple #1
0
def update_department():
    department = Mapper.get_instance().json_to_department(request.json)
    try:
        department_service.update(department)
    except ValueError as err:
        return Response(str(err), 400)
    return Mapper.get_instance().department_to_json(department)
def update_project():
    project = Mapper.get_instance().json_to_project(request.json)
    try:
        project_service.updateProject(project)
    except ValueError as err:
        return Response(str(err), 400)
    return Mapper.get_instance().project_to_json(project)
def get_report_sessions():
    user_id = request.args.get('userid')
    project_id = request.args.get('projectid')
    if user_id is None and project_id is None:
        return jsonify([
            Mapper.get_instance().report_session_to_json(
                x, project_service.getOneProject(x.get_project_id()))
            for x in feedback_service.getAllReportSessions()
        ])

    if user_id is not None:
        try:
            return jsonify([
                Mapper.get_instance().report_session_to_json(
                    x, project_service.getOneProject(x.get_project_id()))
                for x in feedback_service.getAllReportSessionsForUser(user_id)
            ])
        except ValueError as err:
            return Response(str(err), 400)

    if project_id is not None:
        try:
            list = feedback_service.getAllReportSessionsForProject(project_id)
            for x in list:
                x['start_date'] = x['start_date'].strftime(
                    Mapper.get_date_time_format())
                x['end_date'] = x['end_date'].strftime(
                    Mapper.get_date_time_format())
            return jsonify(list)
        except ValueError as err:
            return Response(str(err), 400)
def update_client():
    client = Mapper.get_instance().json_to_client(request.json)
    try:
        client_service.update(client)
    except ValueError as err:
        return Response(str(err), 400)
    return Mapper.get_instance().client_to_json(client)
def update_user():
    user = Mapper.get_instance().json_to_user(request.json)
    try:
        user_service.update(user)
        department = Mapper.get_instance().department_to_json(
            department_service.getOne(user.department_id))
    except ValueError as err:
        return Response(str(err), 400)
    return Mapper.get_instance().user_to_json(user, department)
def delete_report_sessions():
    project_id = request.json['project_id']
    start_date = Mapper.get_instance().json_to_date_time(
        request.json['start_date'])
    end_date = Mapper.get_instance().json_to_date_time(
        request.json['end_date'])
    try:
        count = feedback_service.removeReportSessions(project_id, start_date,
                                                      end_date)
    except ValueError as err:
        return Response(str(err), 400)
    return jsonify(removed=count)
Exemple #7
0
def get_departments():
    department_id = request.args.get('departmentid')
    if department_id is None:
        # get all departments
        return jsonify([
            Mapper.get_instance().department_to_json(department)
            for department in department_service.getAll()
        ])
    else:
        # get one client
        try:
            department = department_service.getOne(department_id)
        except ValueError as err:
            return Response(str(err), 400)
        return Mapper.get_instance().client_to_json(department)
def get_clients():
    client_id = request.args.get('clientid')
    if client_id is None:
        # get all clients
        return jsonify([
            Mapper.get_instance().client_to_json(client)
            for client in client_service.getAll()
        ])
    else:
        # get one client
        try:
            client = client_service.getOne(client_id)
        except ValueError as err:
            return Response(str(err), 400)
        return Mapper.get_instance().client_to_json(client)
def save_user():
    user = Mapper.get_instance().json_to_user(request.json)
    try:
        user_service.send_password_email(
            user
        )  # old, plain text password is used to send it as an email to the user
        print(user.get_password())
        user.set_password(generate_password_hash(
            user.get_password()))  # method : "pbkdf2:sha256"
        user_service.add(user)
        department = Mapper.get_instance().department_to_json(
            department_service.getOne(user.department_id))
    except ValueError as err:
        return Response(str(err), 400)
    return Mapper.get_instance().user_to_json(user, department)
    def get_technologies_and_users_with_recommandation(self):
        technologies = []
        for technology in self.__tech_service.getAll():
            technology = Mapper.get_instance().technology_to_json(technology)
            technology['users'] = []
            for user in self.__user_service.getAll():
                experience_in_days = 0
                for user_project in self.__user_project_repo.getAllForUser(
                        user.id):
                    project = self.__project_repo.getOne(
                        user_project.project_id)
                    project_technology = self.__project_tech_repo.getOne(
                        project.id, technology['id'])
                    if project_technology is not None:
                        difference = (datetime.now().date()
                                      if project.end_date is None else
                                      project.end_date) - project.start_date
                        experience_in_days += difference.days

                technology['users'].append({
                    'id':
                    user.id,
                    'name':
                    user.name,
                    'experienceInDays':
                    experience_in_days
                })

            technologies.append(technology)

        return technologies
def get_users():
    user_id = request.args.get('userid')
    if user_id is None:
        # get all users
        users = []
        for user in user_service.getAll():
            department = Mapper.get_instance().department_to_json(
                department_service.getOne(user.department_id))
            users.append(Mapper.get_instance().user_to_json(user, department))
        return jsonify(users)
    else:
        # get one user
        try:
            user = user_service.getOne(user_id)
            return Mapper.get_instance().user_to_json(user)
        except ValueError as err:
            return Response(str(err), 400)
def get_all_projects():
    project_id = request.args.get('projectid')
    if project_id is None:
        projects_list = []

        for project in project_service.getAllProjects():
            employees = [Mapper.get_instance().user_to_json(x) for x in project_service.getUsersForProject(project.id)]
            technologies = [Mapper.get_instance().technology_to_json(x) for x in project_service.getTechnologiesForProject(project.id)]
            client = Mapper.get_instance().client_to_json(client_service.getOne(project.client_id))
            projects_list.append(Mapper.get_instance().project_to_json(project, employees, technologies, client))

        return jsonify(projects_list)
    else:
        try:
            return Mapper.get_instance().project_to_json(project_service.getOneProject(project_id))
        except ValueError as err:
            return Response(str(err), 400)
def assign_techs():
    project_id = request.args.get('projectid')
    techs = Mapper.get_instance().json_to_technologies(request.json)
    try:
        for tech in techs:
            project_service.assignTechToProject(project_id, tech)
        return jsonify(success=True)
    except ValueError as err:
        return Response(str(err), 400)
def login_post():
    user = userService.matchUserPassword(request.json['email'],
                                         request.json['password'])
    if user is None:
        return json.dumps(user)

    jsonUser = Mapper.get_instance().user_to_json(user)
    jsonUser['jwtToken'] = userService.generate_token(user.id)
    return jsonify(jsonUser)
def get_users():
    project_id = request.args.get('projectid')
    user_id = request.args.get('userid')
    if project_id is not None and user_id is not None:
        return jsonify(assigned=project_service.isUserAssignedToProject(project_id, user_id))

    if project_id is not None:
        try:
            users = project_service.getUsersForProject(project_id)
            return jsonify(
                 [Mapper.get_instance().user_to_json(x, Mapper.get_instance().department_to_json(department_service.getOne(x.get_department_id()))) for x in users])
        except ValueError as err:
            return Response(str(err), 400)

    if user_id is not None:
        try:
            return jsonify([Mapper.get_instance().project_to_json(x) for x in project_service.getProjectsForUser(user_id)])
        except ValueError as err:
            return Response(str(err), 400)
def add_reports():
    from datetime import datetime
    report_session_id = request.args.get('sessionid')
    try:
        count = feedback_service.addReports(
            report_session_id,
            Mapper.get_instance().json_to_reports(request.json),
            datetime.now())
    except ValueError as err:
        return Response(str(err), 400)
    return jsonify(added=count)
def get_technologies():
    project_id = request.args.get('projectid')
    tech_id = request.args.get('techid')
    if project_id is None and tech_id is None:
        return jsonify([Mapper.get_instance().technology_to_json(x) for x in technology_service.getAll()])

    if tech_id is None:
        try:
            return jsonify(
                [Mapper.get_instance().technology_to_json(x) for x in
                 project_service.getTechnologiesForProject(project_id)])
        except ValueError as err:
            return Response(str(err), 400)

    if project_id is None:
        try:
            return Mapper.get_instance().technology_to_json(technology_service.getOne(tech_id))
        except ValueError as err:
          return Response(str(err), 400)

    return jsonify(assigned=project_service.isTechAssignedToProject(project_id, tech_id))
def get_all_skills():
    return jsonify([
        Mapper.get_instance().skill_to_json(x)
        for x in feedback_service.getAllSkills()
    ])