Esempio n. 1
0
def create_user():
    try:
        user_info = google_auth.get_user_info()
        user = User.query.filter_by(user_name=user_info['name']).first()
        if user:
            message = "User already exists"
            user_schema = UserSchema()
            data = user_schema.dump(user).data
            session['user'] = data
            return send_success_response(message)
        if user_info['email'] == "*****@*****.**":
            user = User(user_name=user_info['name'],
                        user_email=user_info['email'],
                        is_admin=True)
        else:
            user = User(user_name=user_info['name'],
                        user_email=user_info['email'])
        db.session.add(user)
        db.session.commit()
        user_schema = UserSchema()
        data = user_schema.dump(user).data
        session['user'] = data
        message = "User created successfully"
        return send_success_response(message)
    except Exception as e:
        message = "Error in creating user"
        return send_error_response(str(e))
Esempio n. 2
0
def get_task_info(task_id):
    try:
        task = Tasks.query.get(task_id)
        if not task:
            message = "There is no task with that id"
            return send_success_response(message)
        task_schema = TaskSchema()
        message = "Successfully retrieved task of " + task.task_title
        data = task_schema.dump(task).data
        return send_success_response(message, data)
    except Exception as e:
        print(e)
        message = "Error in retrieving task of " + str(task_id)
        return send_error_response(message)
Esempio n. 3
0
def get_all_tasks():
    try:
        task = Tasks.query.order_by(desc(Tasks.date)).all()
        if not task:
            message = "There is no task"
            return send_success_response(message)
        task_schema = TaskSchema(many=True)
        data = task_schema.dump(task).data
        message = "Successfully retrieved tasks"
        return send_success_response(message, data)
    except Exception as e:
        print(e)
        message = "Error in retrieving tasks"
        return send_error_response(message)
Esempio n. 4
0
def get_all_projects():
    try:
        project = Project.query.all()
        if not project:
            message = "There is no project available"
            return send_success_response(message)
        project_schema = ProjectSchema(many=True)
        data = project_schema.dump(project).data
        message = "Successfully retrieved projects"
        return send_success_response(message, data)
    except Exception as e:
        print(e)
        message = "Error in retrieving projects"
        return send_error_response(message)
Esempio n. 5
0
def get_task(user_id):
    try:
        user = User.query.get(user_id)
        task = Tasks.query.filter_by(user=user).order_by(desc(
            Tasks.date)).all()
        if not task:
            message = "There is no task of user" + user.user_name
            return send_success_response(message)
        task_schema = TaskSchema(many=True)
        message = "Successfully retrieved task of " + user.user_name
        data = task_schema.dump(task).data
        return send_success_response(message, data)
    except Exception as e:
        print(e)
        message = "Error in retrieving task of " + str(user_id)
        return send_error_response(message)
Esempio n. 6
0
def create_task():
    try:
        project_name = request.json.get('project_name')
        title = request.json.get('task_title')
        status = request.json.get('status')
        reason = request.json.get('reason')
        user_name = session['user']['user_name']
        user_obj = User.query.filter_by(user_name=user_name).first()
        project_obj = Project.query.filter_by(
            project_name=project_name).first()
        user_obj.projects.append(project_obj)
        task = Tasks(task_title=title,
                     status=status,
                     reason=reason,
                     project=project_obj,
                     user=user_obj)
        db.session.add(task)
        db.session.commit()
        message = "Successfully saved task"
        return send_success_response(message)
    except KeyError as e:
        print(e)
        return send_error_response()
    except Exception as e:
        print(e)
        message = "Error in storing task"
        return send_error_response(message)
Esempio n. 7
0
def delete_project(project_id):
    try:
        project = Project.query.get(project_id)
        db.session.delete(project)
        db.session.commit()
        message = "Deleted project successfully"
        return send_success_response(message)
    except Exception as e:
        print(e)
        message = "Error in deleting project"
        return send_error_response(message)
Esempio n. 8
0
def delete_task(task_id):
    try:
        task = Tasks.query.get(task_id)
        db.session.delete(task)
        db.session.commit()
        message = "Deleted task successfully"
        return send_success_response(message)
    except Exception as e:
        print(e)
        message = "Error in deleting task"
        return send_error_response(message)
Esempio n. 9
0
def create_project():
    try:
        project_name = request.json.get('project_name')
        in_report = request.json.get('in_report')
        project = Project(project_name=project_name, in_report=in_report)
        db.session.add(project)
        db.session.commit()
        message = "Successfully created project"
        return send_success_response(message)
    except Exception as e:
        print(e)
        message = "Error in creating projects"
        return send_error_response(message)
Esempio n. 10
0
def update_task(task_id):
    try:
        task = Tasks.query.get(task_id)
        project_name = request.json.get('project_name')
        task.task_title = request.json.get('task_title', task.task_title)
        task.status = request.json.get('status', task.status)
        task.reason = request.json.get('reason', task.reason)
        task.project = Project.query.filter_by(
            project_name=project_name).first()
        db.session.commit()
        task_schema = TaskSchema()
        data = task_schema.dump(task).data
        message = "Successfully updated tasks"
        return send_success_response(message, data)
    except Exception as e:
        print(e)
        message = "Error in updating task"
        return send_error_response(message)