def put(self): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'Admin privilege required.'}, 401 data = _teacher_parser.parse_args() for key in data.keys(): if str(data[key]).lower() in ('none', 'null', ''): data[key] = None teacher_id = data.get("teacher_id") teacher_name = data.get("teacher_name") teacher_code = data.get("teacher_code") if teacher_id: teacher = TeacherModel.find_by_teacher_id(teacher_id) elif teacher_code: teacher = TeacherModel.find_by_teacher_code(teacher_code) elif teacher_name: teacher = TeacherModel.find_by_teacher_name(teacher_name) else: return {"message": "Missing teacher key fields"}, 404 try: data['modified_date'] = datetime.now() if teacher: teacher.set_attribute(data) else: teacher = TeacherModel(**data) teacher.save_to_db() return teacher.json() except Exception as ex: return {"message": f"Error updating teacher data. {repr(ex)}"}, 403
def get(self): data = request.args teacher_id = data.get("teacher_id") teacher_name = data.get("teacher_name") teacher_code = data.get("teacher_code") if teacher_id: teacher = TeacherModel.find_by_teacher_id(teacher_id) if teacher_code: teacher = TeacherModel.find_by_teacher_code(teacher_code) if teacher_name: teacher = TeacherModel.find_by_teacher_name(teacher_name) if teacher: return teacher.json() else: return {"message": "Teacher not found"}, 404
def delete(self): claims = get_jwt_claims() if not claims['is_admin']: return {'message': 'Admin privilege required.'}, 401 data = _teacher_parser.parse_args() teacher_id = data.get("teacher_id") teacher_name = data.get("teacher_name") teacher_code = data.get("teacher_code") if teacher_id: teacher = TeacherModel.find_by_teacher_id(teacher_id) elif teacher_code: teacher = TeacherModel.find_by_teacher_code(teacher_code) else: return {"message": "Missing teacher key fields"}, 404 if teacher: teacher.delete_from_db() return {'message': 'Teacher deleted.'} return {'message': 'Teacher not found.'}, 404