def get_students_by_mentor_id(self, mentor_id): dao = StudentDAO() students = dao.getStudentsByMentorId(mentor_id) result = [] if not students: return jsonify(Error="NOT FOUND"), 404 course_handler = CourseHandler() task_handler = TaskHandler() for s in students: student = self.dicStudent(s) # get student's courses # handler will return a tuple, first element is the response, second element is response status courses = course_handler.get_courses_with_grades_by_student_id( student['user_id']) # if response status is 200 it means there is a result, otherwise no result was found and will be ignored if courses[1] is 200: # response is jsonified, need to get json student['courses'] = courses[0].get_json() # get student's tasks tasks = task_handler.get_all_tasks_by_user_id(student['user_id']) if tasks[1] is 200: student['tasks'] = tasks[0].get_json() result.append(student) return jsonify(result), 200
def get_student_courses(student_id): print(request) print(request.get_json()) if request.method == 'GET': return CourseHandler().get_course(student_id) # elif request.method == 'OPTIONS': # return elif request.method == 'POST': print(request.get_json()) return CourseHandler().insert_course(student_id, request.get_json())
def get_students_with_courses_and_tasks(self): dao = StudentDAO() students = dao.getallstudent() if not students: return jsonify(Error='NOT FOUND'), 404 mapped_result = [] for s in students: student = self.dicStudent(s) courses = CourseHandler().get_courses_with_grades_by_student_id( student['user_id']) print(courses) if courses[1] is 200: student['courses'] = courses[0].get_json() tasks = TaskHandler().get_all_tasks_by_user_id(student['user_id']) if tasks[1] is 200: student['tasks'] = tasks[0].get_json() # student['tasks'] = TaskDAO().get mapped_result.append(student) return jsonify(mapped_result), 200
def insert_grade(student_id): if request.method == 'POST': return CourseHandler().insert_grade(student_id, request.get_json()) elif request.method == 'PUT': cred = request.get_json() grade_id = cred['g_id'] if 'g_name' in cred: return CourseHandler().changeGradeName(grade_id, cred['g_name']) if 'grade' in cred: return CourseHandler().changeGradeGrade(grade_id, cred['grade']) if 'weight' in cred: return CourseHandler().changeGradeWeight(grade_id, cred['weight']) if 'total' in cred: return CourseHandler().changeGradeTotal(grade_id, cred['total']) if 'date' in cred: return CourseHandler().changeGradeDate(grade_id, cred['date'])
def delete_grade(student_id, grade_id): if request.method == 'DELETE': return CourseHandler().deleteGrade(student_id, grade_id)
def get_grades_by_course_id(course_id): print(course_id) return CourseHandler().get_grades_by_course_id(course_id)
def get_student_courses_with_grades(student_id): return CourseHandler().get_courses_with_grades_by_student_id(student_id)
def get_course(course_id,student_id): if request.method == 'GET': return CourseHandler().get_course_by_course_id(course_id, student_id)