def list_classes():  # noqa: E501
    """List all classes

    Returns all classes # noqa: E501


    :rtype: None
    """
    select_string = """
            SELECT * FROM class
            """
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        res = []
        for row in result:
            res.append({
                'class_dept': row["class_dept"],
                'class_number': row["class_number"],
                'class_level': row["class_level"],
                'name': row["name"],
                'description': row["description"],
                'credit_hours': row["credit_hours"]
            })
        return res, 200
    except exc.IntegrityError:
        return "Internal Server Error", 500
Example #2
0
def list_colleges():  # noqa: E501
    """List all colleges

    Returns all colleges # noqa: E501

    :param college_id: ID of college to return
    :type college_id: int

    :rtype: None
    """
    select_string = """
                SELECT * FROM college
                """
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        res = []
        for row in result:
            r = College.from_dict(row)
            res.append({
                'name': row["name"],
                'id': row["id"],
            })
        return res, 200
    except exc.IntegrityError:
        return "Internal Server Error", 500
Example #3
0
def get_pursued_degree_by_nuid(nuid):  # noqa: E501
    """List pursued_degree by NUID

    Returns the pursued_degrees related to the given NUID # noqa: E501

    :param nuid: nuid of the user related to the pursued_degree to return
    :type nuid: int

    :rtype: None
    """
    select_string = """
        SELECT * FROM pursued_degree
        WHERE
            nuid = {};
        """.format(nuid)
    try:
        session_cookie = connexion.request.cookies.get("session")
        session_NUID = connexion.JWT_verify(session_cookie)
        if session_NUID == str(nuid).zfill(9):
            db_conn = connexion.DB(connexion.DB_ENG)
            result = db_conn.execute(select_string)
            db_conn.close()
            res = []
            for nuid, degree_id in result.fetchall():
                r = PursuedDegree(nuid, degree_id)
                res.append(r)
            return res, 201
        else:
            return "Forbidden", 403
    except exc.IntegrityError as err:
        return "Could not add pursued degree", 406
    except KeyError:
        return "Forbidden", 403
def get_student_by_nuid(nuid):  # noqa: E501
    """Get student by nuid

     # noqa: E501

    :param nuid: The name that needs to be fetched. Use student1 for testing.
    :type nuid: int

    :rtype: Student
    """
    select_string = """
        SELECT
            name,
            email,
            nuid
        FROM
            student
        WHERE
            nuid = {}
        """.format(nuid)
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        for row in result:
            res = {
                'name': row["name"],
                'nuid': row["nuid"],
                'email': row["email"]
            }
            res = Student.from_dict(res)
            return res, 200
        return "Object not found", 404
    except exc.IntegrityError:
        return "Internal Server Error", 500
Example #5
0
def delete_pursued_degree(nuid, degree_id):  # noqa: E501
    """Deletes a pursued_degree

     # noqa: E501

    :param nuid: nuid of the user related to the pursued_degree to return
    :type nuid: int
    :param degree_id: nuid of the degree related to the pursued_degree to return
    :type degree_id: int

    :rtype: None
    """

    delete_string = "DELETE FROM pursued_degree WHERE nuid = {0} AND degree_id = {1};".format(
        nuid, degree_id)
    try:
        session_cookie = connexion.request.cookies.get("session")
        session_NUID = connexion.JWT_verify(session_cookie)
        if session_NUID == str(nuid).zfill(9):
            db_conn = connexion.DB(connexion.DB_ENG)
            result = db_conn.execute(delete_string)
            db_conn.close()
            return "Accepted", 201
        else:
            return "Forbidden", 403
    except exc.IntegrityError:
        return "Could not add pursued degree", 406
    except KeyError:
        return "Forbidden", 403
Example #6
0
def list_department():  # noqa: E501
    """List all departments

     # noqa: E501


    :rtype: None
    """
    select_string = """
            SELECT * FROM department
            """
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        res = []
        for row in result:
            r = Department.from_dict(row)
            res.append({
                'short_name': row["short_name"],
                'long_name': row["long_name"],
                'college_id': row["college_id"]
            })
        return res, 200
    except exc.IntegrityError:
        return "Internal Server Error", 500
def add_schedule_option(body):  # noqa: E501
    """Add a schedule_option to the classdeck

     # noqa: E501

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

    :rtype: None
    """
    if connexion.request.is_json:
        json = connexion.request.get_json()
        body = ScheduleOption.from_dict(json)  # noqa: E501
        insert_string = """
                    INSERT INTO schedule_option (nuid, title, semester_id)
                    VALUES ({0}, '{1}', {2});
                    """.format(json["nuid"], json["title"], json["semester"])
        try:
            session_cookie = connexion.request.cookies.get("session")
            session_NUID = connexion.JWT_verify(session_cookie)
            if session_NUID == str(body.nuid).zfill(9):
                db_conn = connexion.DB(connexion.DB_ENG)
                trans = db_conn.begin()
                result = db_conn.execute(insert_string)
                trans.commit()
                db_conn.close()
                return ["Accepted", result.lastrowid], 201
            else:
                return "Forbidden", 403
        except exc.IntegrityError as err:
            return "Could not add pursued degree", 406
        except KeyError:
            return "Forbidden", 403
    return "Bad Request", 400
def add_schedule_option_section(body):  # noqa: E501
    """Add a schedule_option_section to the classdeck

     # noqa: E501

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

    :rtype: None
    """

    if connexion.request.is_json:
        body = ScheduleOptionSection.from_dict(
            connexion.request.get_json())  # noqa: E501
        insert_string = """
                    INSERT IGNORE INTO schedule_option_section (schedule_option_id, section_crn)
                        VALUES ({0}, {1})
                    """.format(body.schedule_id, body.crn)
        try:
            session_cookie = connexion.request.cookies.get("session")
            session_NUID = connexion.JWT_verify(session_cookie)
            db_conn = connexion.DB(connexion.DB_ENG)
            result = db_conn.execute(insert_string)
            db_conn.close()
            return ["Accepted", result.lastrowid], 201
        except exc.IntegrityError as err:
            return "Could add section for schedule_option", 406
        except KeyError:
            return "Forbidden", 403
        except exc.InternalError as err:
            return err.orig.args[1], 406
    return "Bad Request", 400
def get_attribute_by_name(attribute_name):  # noqa: E501
    """Find attribute by name

    Returns a single attribute # noqa: E501

    :param attribute_name: name of attribute to return
    :type attribute_name: str

    :rtype: Attribute
    """
    select_string = """
        SELECT * FROM attributes
        WHERE name = "{}"
        """.format(attribute_name)
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        for row in result:
            res = {'name': row["name"], 'nupath': row["nu_path"]}
            res = Attribute.from_dict(res)
            return res, 200
        return "Object not found", 404
    except exc.IntegrityError:
        return "Internal Server Error", 500
def delete_schedule_option_section(schedule_id, crn):  # noqa: E501
    """Deletes a schedule_option_section

     # noqa: E501

    :param schedule_id: ID of the schedule related to the schedule_option_section to return
    :type schedule_id: int
    :param crn: crn of the section related to the schedule_option_section to return
    :type crn: int

    :rtype: None
    """

    delete_string = "DELETE FROM schedule_option_section WHERE schedule_option_id = {0} AND section_crn = {1};"\
        .format(schedule_id, crn)
    try:
        session_cookie = connexion.request.cookies.get("session")
        session_NUID = connexion.JWT_verify(session_cookie)
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(delete_string)
        db_conn.close()
        return "Accepted", 201
    except exc.IntegrityError:
        return "Could not remove section", 202
    except KeyError:
        return "Forbidden", 403
def list_sections_by_class(semester_id, class_department, class_number):
    select_string = """
                    SELECT * 
                    FROM section AS s
                    WHERE s.semester_id = {0}
                      AND s.class_dept = "{1}"
                      AND s.class_number = {2};
                    """.format(semester_id, class_department, class_number)
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        res = []
        for row in result:
            r = Section.from_dict(row)
            res.append({
                'crn': row["crn"],
                'class_dept': row["class_dept"],
                'class_number': row["class_number"],
                'professor': row["professor"],
                'capacity': row["capacity"],
                'registered': row["registered"]
            })
        return res, 200
    except exc.IntegrityError:
        return "Internal Server Error", 500
def delete_student_taken_classes(nuid, class_dept, class_number):  # noqa: E501
    """Deletes a student_taken_classes

     # noqa: E501

    :param nuid: nuid of the student related to the student_taken_classes to return
    :type nuid: int
    :param class_dept: short code of the department of the class related to the student_taken_classes to return
    :type class_dept: str
    :param class_number: number of the class related to the student_taken_classes to return
    :type class_number: int

    :rtype: None
    """
    delete_string = """
            DELETE FROM classes_taken 
            WHERE nuid = {0} 
              AND class_dept = '{1}'
              AND class_number = {2};
            """.format(nuid, class_dept, class_number)
    try:
        session_cookie = connexion.request.cookies.get("session")
        session_NUID = connexion.JWT_verify(session_cookie)
        if session_NUID == str(nuid).zfill(9):
            db_conn = connexion.DB(connexion.DB_ENG)
            result = db_conn.execute(delete_string)
            db_conn.close()
            return "Accepted", 201
        else:
            return "Forbidden", 403
    except exc.IntegrityError:
        return "Could delete classes taken", 406
    except KeyError:
        return "Forbidden", 403
def get_class_by_id(class_department, class_number):  # noqa: E501
    """Find class by ID

    Returns a single class # noqa: E501

    :param class_department: short code of the department that offers the class to return
    :type class_department: str
    :param class_number: class number of the class to return
    :type class_number: int

    :rtype: ModelClass
    """
    select_string = """
                    SELECT * FROM class
                    WHERE class_dept = "{0}" AND class_number = "{1}"
                    """.format(class_department, class_number)
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        for row in result:
            res = {
                'class_dept': row["class_dept"],
                'class_number': row["class_number"],
                'class_level': row["class_level"],
                'name': row["name"],
                'description': row["description"],
                'credit_hours': row["credit_hours"]
            }
            return res, 200
        return "Object not found", 404
    except exc.IntegrityError:
        return "Internal Server Error", 500
Example #14
0
def add_pursued_degree(body):  # noqa: E501
    """Add a pursued_degree to the classdeck

     # noqa: E501

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

    :rtype: None
    """
    if connexion.request.is_json:
        body = PursuedDegree.from_dict(
            connexion.request.get_json())  # noqa: E501
        insert_string = """
            INSERT IGNORE INTO pursued_degree (
                nuid,
                degree_id)
            VALUES ({0}, {1});
            """.format(body.nuid, body.degree_id)
        try:
            session_cookie = connexion.request.cookies.get("session")
            session_NUID = connexion.JWT_verify(session_cookie)
            if session_NUID == str(body.nuid).zfill(9):
                db_conn = connexion.DB(connexion.DB_ENG)
                result = db_conn.execute(insert_string)
                db_conn.close()
                return "Accepted", 201
            else:
                return "Forbidden", 403
        except exc.IntegrityError as err:
            return "Could not add pursued degree", 406
        except KeyError:
            return "Forbidden", 403
    return "Bad Request", 400
def delete_student(nuid):  # noqa: E501
    """Delete student

    This can only be done by the logged in student. # noqa: E501

    :param nuid: The nuid that needs to be deleted
    :type nuid: str

    :rtype: None
    """
    delete_string = """
        DELETE FROM student
        WHERE nuid = "{}"
        """.format(nuid)
    try:
        session_cookie = connexion.request.cookies.get("session")
        session_NUID = connexion.JWT_verify(session_cookie)
        db_conn = connexion.DB(connexion.DB_ENG)
        db_conn.execute(delete_string)
        db_conn.close()
        return "Deleted", 204
    except exc.IntegrityError:
        return "Could not delete object", 403
    except KeyError:
        return "Forbidden", 403
def list_classes_by_semester(semester):
    select_string = """
                SELECT
                    DISTINCT
                    c.class_dept,
                    c.class_number,
                    c.class_level,
                    c.name,
                    c.description,
                    c.credit_hours
                FROM class AS c
                RIGHT OUTER JOIN section AS s ON c.class_dept = s.class_dept AND c.class_number = s.class_number
                WHERE s.semester_id = {0};
                """.format(semester)
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        res = []
        for row in result:
            res.append({
                'class_dept': row["class_dept"],
                'class_number': row["class_number"],
                'class_level': row["class_level"],
                'name': row["name"],
                'description': row["description"],
                'credit_hours': row["credit_hours"]
            })
        if len(res) > 0:
            return res, 200
        else:
            return "No classes found", 404
    except exc.IntegrityError:
        return "Internal Server Error", 500
def update_student(body):  # noqa: E501
    """Updated student

    This can only be done by the logged in student. # noqa: E501

    :param nuid: nuid that need to be updated
    :type nuid: int
    :param body: Updated student object
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = Student.from_dict(connexion.request.get_json())  # noqa: E501
        update_string = """
            UPDATE student
            SET pass = "******"
            WHERE nuid = {0};
            """.format(body.nuid, body.password)
        try:
            session_cookie = connexion.request.cookies.get("session")
            session_NUID = connexion.JWT_verify(session_cookie)
            db_conn = connexion.DB(connexion.DB_ENG)
            db_conn.execute(update_string)
            db_conn.close()
            return "Accepted", 201
        except exc.IntegrityError:
            return "Already Exists", 202
        except KeyError:
            return "Forbidden", 403
    return "Bad Request", 400
def list_degrees_by_college(college_id):  # noqa: E501
    """List all degrees in the given college

     # noqa: E501

    :param college_id: ID of college related to the degrees to return
    :type college_id: int

    :rtype: None
    """
    select_string = """
                        SELECT * FROM degree
                        WHERE college_id = "{}"
                        """.format(college_id)
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        for row in result:
            res = {
                'name': row["name"],
                'degree_id': row["degree_id"],
                'degree_type': row["degree_type"],
                'college_id': row["college_id"]
            }
            return res, 200
        return "Object not found", 404
    except exc.IntegrityError:
        return "Internal Server Error", 500
Example #19
0
def get_department_by_short_code(department_short_code):  # noqa: E501
    """Find department by short code

    Returns a single department # noqa: E501

    :param department_short_code: short code of department to return
    :type department_short_code: str

    :rtype: Department
    """
    select_string = """
            SELECT * FROM department
            WHERE short_name = "{}"
            """.format(department_short_code)
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        for row in result:
            res = {
                'short_name': row["short_name"],
                'long_name': row["long_name"],
                'college_id': row["college_id"]
            }
            return res, 200
        return "Object not found", 404
    except exc.IntegrityError:
        return "Internal Server Error", 500
def list_sections():  # noqa: E501
    """Lists all sections

     # noqa: E501


    :rtype: None
    """
    select_string = """
                SELECT * FROM section
                """
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        res = []
        for row in result:
            r = Section.from_dict(row)
            res.append({
                'crn': row["crn"],
                'class_dept': row["class_dept"],
                'class_number': row["class_number"],
                'professor': row["professor"],
                'capacity': row["capacity"],
                'registered': row["registered"]
            })
        return res, 200
    except exc.IntegrityError:
        return "Internal Server Error", 500
Example #21
0
def get_semester_by_id(semester_id):
    select_string = "SELECT * FROM semester WHERE id = {};".format(semester_id)
    db_conn = connexion.DB(connexion.DB_ENG)
    result = db_conn.execute(select_string)
    db_conn.close()
    for id, year, semester in result.fetchall():
        r = {"id": id, "year": year, "semester": semester}
        return r, 200
    return "Not found", 404
Example #22
0
def list_semesters():
    select_string = "SELECT * FROM semester;"
    db_conn = connexion.DB(connexion.DB_ENG)
    result = db_conn.execute(select_string)
    db_conn.close()
    res = []
    for id, year, semester in result.fetchall():
        r = {"id": id, "year": year, "semester": semester}
        res.append(r)
    return res, 200
def logged_in_student_data():
    session_cookie = connexion.request.cookies.get("session")
    session_NUID = connexion.JWT_verify(session_cookie)
    select_string = "SELECT * FROM student WHERE nuid = {}".format(
        session_NUID)
    db_conn = connexion.DB(connexion.DB_ENG)
    result = db_conn.execute(select_string)
    db_conn.close()
    res = []
    for r in result.fetchall():
        res.append({"nuid": r["nuid"], "email": r["email"], "name": r["name"]})
    if len(res) > 0:
        return res, 200
    else:
        return "User not logged in.", 400
def restrictions_by_crn(crn):
    select_string = """
                    SELECT * FROM restriction
                    WHERE crn = {}
                    """.format(crn)
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        res = []
        for row in result:
            res.append({'crn': row["crn"], 'type': row[type]})
        return res, 200
    except exc.IntegrityError:
        return "Internal Server Error", 500
def update_schedule_option():
    if connexion.request.is_json:
        body: ScheduleOption = ScheduleOption.from_dict(connexion.request.get_json())  # noqa: E501
        update_string = """
            UPDATE schedule_option
            SET title  = "{1}"
            WHERE schedule_option_id = {0};
            """.format(body.schedule_id, body.title)
        try:
            session_cookie = connexion.request.cookies.get("session")
            session_NUID = connexion.JWT_verify(session_cookie)
            db_conn = connexion.DB(connexion.DB_ENG)
            db_conn.execute(update_string)
            db_conn.close()
            return "Accepted", 201
        except exc.IntegrityError:
            return "Already Exists", 202
        except KeyError:
            return "Forbidden", 403
    return "Bad Request", 400
def get_student_taken_classes_by_nuid(nuid):  # noqa: E501
    """Find student_taken_classes by ID

    Returns a single student_taken_classes # noqa: E501

    :param nuid: nuid of the student related to the student_taken_classes to return
    :type nuid: int
    :param class_dept: short code of the department of the class related to the student_taken_classes to return
    :type class_dept: str
    :param class_number: number of the class related to the student_taken_classes to return
    :type class_number: int

    :rtype: StudentTakenClasses
    """
    select_string = """
            SELECT nuid, class_dept, class_number, transferred, current 
            FROM classes_taken
            WHERE
                nuid = {};
            """.format(nuid)
    try:
        session_cookie = connexion.request.cookies.get("session")
        session_NUID = connexion.JWT_verify(session_cookie)
        if session_NUID == str(nuid).zfill(9):
            db_conn = connexion.DB(connexion.DB_ENG)
            result = db_conn.execute(select_string)
            db_conn.close()
            res = []
            for nuid, class_dept, class_number, transferred, current in result.fetchall(
            ):
                r = StudentTakenClasses(nuid, class_dept, class_number,
                                        transferred, current)
                res.append(r)
            return res, 201
        else:
            return "Forbidden", 403
    except KeyError:
        return "Forbidden", 403
    except AttributeError:
        return "Forbidden", 403
def list_attributes():  # noqa: E501
    """List all attributes

    Returns all attributes # noqa: E501


    :rtype: None
    """
    select_string = """
                SELECT * FROM attributes
                """
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        res = []
        for row in result:
            r = Attribute.from_dict(row)
            res.append({'name': row["name"], 'nupath': row["nupath"]})
        return res, 200
    except exc.IntegrityError:
        return "Internal Server Error", 500
def delete_schedule_option(schedule_option_id):  # noqa: E501
    """Deletes a schedule_option

     # noqa: E501

    :param schedule_option_id: ScheduleOption id to delete
    :type schedule_option_id: int

    :rtype: None
    """
    delete_string = "DELETE FROM schedule_option WHERE schedule_option_id = {0};".format(schedule_option_id)
    try:
        session_cookie = connexion.request.cookies.get("session")
        session_NUID = connexion.JWT_verify(session_cookie)
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(delete_string)
        db_conn.close()
        return "Accepted", 201
    except exc.IntegrityError:
        return "Could not delete schedule option", 406
    except KeyError:
        return "Forbidden", 403
def login_student(nuid, password):  # noqa: E501
    """Logs student into the system

     # noqa: E501

    :param nuid: The nuid for login
    :type nuid: str
    :param password: The password for login in clear text
    :type password: str

    :rtype: str
    """
    select_string = """
        SELECT
            name,
            email,
            nuid
        FROM
            student
        WHERE
            nuid = {0}
            AND
            pass = "******";
        """.format(nuid, password)
    db_conn = connexion.DB(connexion.DB_ENG)
    result = db_conn.execute(select_string)
    db_conn.close()

    for row in result:
        resp = make_response("Student is now logged in", 200)
        session = connexion.JWT_generate_token(nuid)
        resp.set_cookie("session", session)
        return resp
    else:
        resp = make_response(
            "Wrong User/Password Combination. Please try again.", 403)
        session = 'logged_out'
        resp.set_cookie("session", session)
        return resp
def list_degrees():  # noqa: E501
    """List all degrees

     # noqa: E501


    :rtype: None
    """
    select_string = """
            SELECT * FROM degree;
            """
    try:
        db_conn = connexion.DB(connexion.DB_ENG)
        result = db_conn.execute(select_string)
        db_conn.close()
        res = []
        for name, degree_id, degree_type, college_id in result.fetchall():
            r = Degree(degree_id, name, college_id, degree_type)
            res.append(r)
        return res, 200
    except exc.IntegrityError:
        return "Internal Server Error", 500