def insert_study_task(self, user_id, form): print('form', form) print(form['task_name']) if len(form) is not 5 and len(form) is not 4: return jsonify(Error="Malformed post request"), 400 else: task_name = form['task_name'] # task_description = form['task_description'] if form['task_description'] else None if form['task_description']: task_description = form['task_description'] else: task_description = None start_time = form['start_time'] end_time = form['end_time'] course_id = form['course_id'] finished = False if task_name and start_time and end_time and course_id: dao = TaskDAO() task_id = dao.add_study_task(task_name, task_description, start_time, end_time, finished, course_id) dao.add_task_to_user(user_id, task_id) return jsonify({'task_id': task_id[0]}), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def insert_personal_task(self, user_id, form): print('form', form) print(len(form)) if len(form) is not 4 and len(form) is not 3: return jsonify(Error="Malformed post request"), 400 else: print('form', form) task_name = form['task_name'] if form['task_description']: task_description = form['task_description'] else: task_description = None start_time = form['start_time'] end_time = form['end_time'] finished = False if task_name and start_time and end_time: dao = TaskDAO() task_id = dao.add_personal_task(task_name, task_description, start_time, end_time, finished) dao.add_task_to_user(user_id, task_id) # result = self.mapToTaskDict(task_id) return jsonify({'task_id': task_id[0]}), 200 else: return jsonify( Error="Unexpected attributes in post request"), 400
def get_course_task_count_by_user_id(self, user_id): dao = TaskDAO() result = dao.get_course_task_count_by_user_id(user_id) if not result: return jsonify(Error="NOT FOUND"), 404 print(result) return jsonify(result)
def get_course_by_course_id(self, course_id, student_id): dao = CourseDAO() result = dao.get_course_by_course_id(course_id, student_id) if not result: return jsonify(Error='NOT FOUND'), 404 course = self.mapToCourseDict(result) section_id = result[5] enrolled_id = result[6] course['time'] = [] course['grades'] = [] course['tasks'] = [] # get time schedule of section time = dao.get_section_times_by_section_id(section_id) if time: for t in time: course['time'].append(self.mapToTimeDict(t)) # get grades of course grades = dao.get_grades_by_enrolled_id(enrolled_id) if grades: for g in grades: print(g) course['grades'].append(self.mapToGradeDict(g)) # get tasks of course dao2 = TaskDAO() tasks = dao2.get_study_tasks_by_user_id_and_course_id( student_id, course['course_id']) if tasks: for t in tasks: course['tasks'].append(self.mapToTaskDict(t)) return jsonify(Course=course)
def get_appointment_tasks_by_user_id(self, user_id): dao = TaskDAO() result = dao.get_appointment_tasks_by_user_id(user_id) if not result: return jsonify(Error="NOT FOUND"), 404 mapped_result = [] for r in result: mapped_result.append(self.mapToTaskDict(r)) return jsonify(mapped_result)
def get_all_tasks(self): dao = TaskDAO() result = dao.get_all_tasks() if not result: return jsonify(Error="NOT FOUND"), 404 mapped_result = [] for r in result: mapped_result.append(self.mapToTaskDict(r)) return jsonify(mapped_result)
def get_study_task_by_user_id_and_course_id(self, user_id, course_id): dao = TaskDAO() result = dao.get_study_tasks_by_user_id_and_course_id( user_id, course_id) if not result: return jsonify(Error="NOT FOUND"), 404 mapped_result = [] for r in result: mapped_result.append(self.mapToTaskDict(r)) return jsonify(mapped_result)
def get_courses(self, user_id): dao = TaskDAO() #just trying it make it work pero se que esta mal result = dao.get_all_courses() if not result: return jsonify(Error="NOT FOUND"), 404 mapped_result = [] for r in result: mapped_result.append(self.mapCourseName(r)) print(mapped_result) return jsonify(mapped_result)
def get_courses_with_grades_by_student_id(self, student_id): dao = CourseDAO() courses = dao.get_courses_by_student_id(student_id) if not courses: return jsonify(Error="NOT FOUND"), 404 mapped_result = [] for c in courses: print(c) course = self.mapToCourseDict(c) section_id = c[5] enrolled_id = c[6] print(course) course['time'] = [] course['grades'] = [] course['tasks'] = [] # get time schedule of section time = dao.get_section_times_by_section_id(section_id) if time: for t in time: course['time'].append(self.mapToTimeDict(t)) # get grades of course grades = dao.get_grades_by_enrolled_id(enrolled_id) if grades: for g in grades: print(g) course['grades'].append(self.mapToGradeDict(g)) # get tasks of course dao2 = TaskDAO() tasks = dao2.get_study_tasks_by_user_id_and_course_id( student_id, course['course_id']) if tasks: for t in tasks: course['tasks'].append(self.mapToTaskDict(t)) mapped_result.append(course) return jsonify(mapped_result), 200
def get_all_tasks_by_user_id(self, user_id): dao = TaskDAO() mapped_result = [] # get course tasks course = dao.get_course_tasks_by_user_id(user_id) if course: for t in course: task = self.mapToTaskDict(t) task['type'] = 'course' mapped_result.append(task) # get study tasks study = dao.get_study_tasks_by_user_id(user_id) if study: for t in study: task = self.mapToTaskDict(t) task['type'] = 'study' mapped_result.append(task) # get personal tasks personal = dao.get_personal_tasks_by_user_id(user_id) if personal: for t in personal: task = self.mapToTaskDict(t) task['type'] = 'personal' mapped_result.append(task) # get appointment tasks appointment = dao.get_appointment_tasks_by_user_id(user_id) if appointment: for t in appointment: task = self.mapToTaskDict(t) task['type'] = 'appointment' mapped_result.append(task) if not mapped_result: return jsonify(Error='NOT FOUND'), 404 return jsonify(mapped_result), 200