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 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 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
Пример #4
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
Пример #5
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
Пример #6
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
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 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 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 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 duplicate_schedule_option(sch_opt_id):
    try:
        session_cookie = connexion.request.cookies.get("session")
        session_NUID = connexion.JWT_verify(session_cookie)
        db_conn = connexion.DB_ENG.raw_connection()
        cursor = db_conn.cursor()
        cursor.callproc("duplicate_schedule_option", [sch_opt_id])
        db_conn.commit()
        cursor.close()
        db_conn.close()
        return "Accepted", 200
    except exc.IntegrityError:
        return "Server error", 500
    except KeyError:
        return "Forbidden", 403
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 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 add_student_taken_classes(body):  # noqa: E501
    """Add a student_taken_classes to the classdeck

     # noqa: E501

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

    :rtype: None
    """
    if connexion.request.is_json:
        body = StudentTakenClasses.from_dict(
            connexion.request.get_json())  # noqa: E501
        insert_string = """
            INSERT IGNORE INTO classes_taken (
                nuid,
                class_dept,
                class_number,
                current,
                transferred)
            VALUES ({0}, "{1}", {2}, {3}, {4});
            """.format(body.nuid, body.class_dept, body.class_number,
                       body.current, body.transferred)
        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 classes taken", 406
        except KeyError:
            return "Forbidden", 403
    return "Bad Request", 400
def get_schedule_option_by_nuid(nuid):  # noqa: E501
    """List schedule_option by NUID

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

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

    :rtype: None
    """
    select_string = """
            SELECT
                DISTINCT
                opt.schedule_option_id, 
                opt.title, 
                opt.semester_id, 
                sec.crn, 
                sec.class_dept, 
                sec.class_number, 
                sec.professor,
                mt.start_time,
                mt.end_time,
                mt.meeting_days,
                cls.name,
                cls.description,
                satisfies_degree_requirement({0}, cls.class_dept, cls.class_number) AS part_of_degree
            FROM schedule_option AS opt
            LEFT OUTER JOIN schedule_option_section AS opt_s ON opt.schedule_option_id = opt_s.schedule_option_id
            LEFT OUTER JOIN section AS sec ON opt_s.section_crn = sec.crn
            LEFT OUTER JOIN meeting_times AS mt ON sec.crn = mt.crn
            LEFT OUTER JOIN class AS cls ON (sec.class_dept = cls.class_dept AND sec.class_number = cls.class_number)
            WHERE nuid = {0};
            """.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 = []
            opt = {
                "schedule_option_id": -1,
                "nuid": -1,
                "title": -1,
                "semester_id": -1,
                "sections": []
            }
            for schedule_option_id, title, semester_id, crn, class_dept, \
                class_number, professor, start_time, end_time, meeting_days, \
                cname, cdesc, part_of_degree in result.fetchall():
                if opt["schedule_option_id"] == schedule_option_id:
                    mapped_crns = list(map(lambda s: s["crn"], opt["sections"]))
                    if crn not in mapped_crns:
                        opt["sections"].append({
                            "class_dept": class_dept,
                            "class_number": class_number,
                            "professor": professor,
                            "crn": crn,
                            "cname": cname,
                            "cdesc": cdesc,
                            "part_of_degree": part_of_degree
                        })
                else:
                    if opt["schedule_option_id"] != -1:
                        res.append(opt)
                    opt = {
                        "schedule_option_id": schedule_option_id,
                        "nuid": nuid,
                        "title": title,
                        "semester_id": semester_id,
                        "sections": []
                    }
                    if crn is not None:
                        mapped_crns = list(map(lambda s: s["crn"], opt["sections"]))
                        if crn not in mapped_crns:
                            opt["sections"].append({
                                "class_dept": class_dept,
                                "class_number": class_number,
                                "professor": professor,
                                "crn": crn,
                                "cname": cname,
                                "cdesc": cdesc,
                                "part_of_degree": part_of_degree
                            })
            if opt["schedule_option_id"] != -1:
                res.append(opt)
            return res, 201
        else:
            return "Forbidden", 403
    except exc.IntegrityError as err:
        return "Could not add pursued degree", 406
    except KeyError:
        return "Forbidden", 403