def delete(e): try: delStudent = request.get_json() user_id = delStudent.get('delUserID') Lecture.deleteRecord(user_id) return jsonify({'status': 'success'}), 200 except Exception as e: return jsonify({ 'status': 'bad-request', 'error_message': e.__str__() }), 400
def search_record(e): try: searchName = request.args.get('searchName') searchRecord = Lecture.searchLecturerRecord(str(searchName)) return jsonify({ 'status': 'success', 'search_results': searchRecord, }), 200 except: return jsonify({'status': 'bad-request'}), 400
def create_lecturer_course(e): try: new_lecturer_course = request.get_json() course_id = new_lecturer_course.get('course_id') user_id = new_lecturer_course.get('new_user_id') isCreated = Lecture.createRecordByCourse(course_id, user_id) if isCreated is True: return jsonify({'status': 'success'}), 200 else: return jsonify({'status': 'already-exist'}), 202 except: return jsonify({'status': 'bad-request'}), 400
def search_record_from_course(e): try: course_id = request.args.get('course_id') searchName = request.args.get('searchName') searchRecord = Lecture.searchLecturerRecordFromCourse( course_id, str(searchName), 'in_course') return jsonify({ 'status': 'success', 'search_results': searchRecord, }), 200 except: return jsonify({'status': 'bad-request'}), 400
def search_record_outside_course(e): try: course_id = request.args.get('course_id') searchName = request.args.get('searchName') searchRecord = Lecture.searchLecturerRecordFromCourse( course_id, str(searchName), 'outside_course') return jsonify({ 'status': 'success', 'search_results': searchRecord, }), 200 except Exception as e: return jsonify({ 'status': 'bad-request', 'error_message': e.__str__() }), 400
def get_records(e): try: page_index = request.args.get('page_index') per_page = request.args.get('per_page') sort_field = request.args.get('sort_field') sort_order = request.args.get('sort_order') record = Lecture.getRecord(page_index, per_page, sort_field, sort_order) return jsonify({ 'status': 'success', 'records': record[0], 'page_number': record[1].page_number, 'page_size': record[1].page_size, 'num_pages': record[1].num_pages, 'total_results': record[1].total_results }), 200 except: return jsonify({'status': 'bad-request'}), 400
def update_record(e): try: new_update = request.get_json() user_id = new_update.get('user_id') username = new_update.get('update_username') name = new_update.get('update_name') email = new_update.get('update_email') updated_at = datetime.now( pytz.timezone('Asia/Ho_Chi_Minh')).strftime("%Y-%m-%d %H:%M:%S") actived = new_update.get('update_actived') is_lock = new_update.get('update_is_lock') isUpdated = Lecture.updateRecord(int(user_id), str(username).strip(), str(name).strip(), str(email).strip(), updated_at, actived, is_lock) if isUpdated is True: return jsonify({'status': 'success'}), 200 else: return jsonify({'status': 'already-exist'}), 202 except: return jsonify({'status': 'bad-request'}), 400