Пример #1
0
def resolve_student(_, info, **kwargs):
    # return "user"
    id = kwargs.get("id", None)
    user = None
    if id:
        user = StudentModel.find_by_id(id)
    return user
Пример #2
0
    def put(self, id):
        data = Student.parser.parse_args()
        student = StudentModel.find_by_id(id)

        if student is None:
            student = StudentModel(id, **data)
        else:
            student.name = data["name"]
            student.degree_id = data["degree_id"]

        student.save_to_db()

        return student.json(), 201
Пример #3
0
def resolve_class(_, info, **kwargs):
    id = kwargs.get("id", None)
    clazz = None
    studentList = []
    if id:
        clazz = ClassModel.find_by_id(id)
        if clazz:
            maps = ClassStudentModel.find_by_class_id(id)
            if maps:
                for classStudent in maps:
                    student = StudentModel.find_by_id(classStudent.studentId)
                    studentList.append(student)
            return {"id": id, "name": clazz.name, "students": studentList}
    return {"id": id, "name": "class not found", "students": []}
Пример #4
0
    def post(self, id):
        if StudentModel.find_by_id(id):
            return {
                "message": "A student with id {} already exists".format(id)
            }, 400

        data = Student.parser.parse_args()
        student = StudentModel(id, **data)

        try:
            student.save_to_db()
        except:
            return {"message", "An error occured creating the student."}, 500

        return student.json(), 201
Пример #5
0
def resolve_add_student_to_class(_, info, classId, studentId):

    clazz = ClassModel.find_by_id(classId)
    student = StudentModel.find_by_id(studentId)
    if clazz and student:
        classStudent = ClassStudentModel.find_by_class_id_student_id(
            classId, studentId)
        if not classStudent:
            csmMap = ClassStudentModel(classId, studentId)
            csmMap.save_to_db()
        return {"id": clazz.id, "name": clazz.name, "students": [student]}
    return {
        "id": classId,
        "name": "student or class not found",
        "students": []
    }
Пример #6
0
 def put(self, id):
     user = UserModel.find_by_id(get_jwt_identity())
     if not user:
         return {"message": "not authenticated"}, 401
     claims = get_jwt_claims()
     if not (claims['type'] == 'admin' or user.id == id or (claims['type'] == 'teacher' and user.allowed == True)):
         return {"message": "not authenticated"}, 401
     data = Student.parser.parse_args()
     student = StudentModel.find_by_id(id)
     if not student:
         return {"message": "Student not found."}, 404
     if data['email'] is not None:
         student.email = data['email']
     if data['password'] is not None:
         student.password = data['password']
     if data['course'] is not None:
         student.course = data['course']
     student.save_to_db()
     return {"message": "Student detail updated"}, 200
Пример #7
0
def identity(payload):
    identity = payload["identity"]
    return StudentModel.find_by_id(identity)
Пример #8
0
 def delete(self, id):
     student = StudentModel.find_by_id(id)
     if not student:
         return {'messsage': 'Student not found'}, 404
     student.delete_from_db()
     return {'message': 'Student deleted.'}, 200
Пример #9
0
 def get(self, id):
     student = StudentModel.find_by_id(id)
     if not student:
         return {"message": "Student not found"}, 404
     return student.json(), 200
Пример #10
0
 def delete(self, id):
     student = StudentModel.find_by_id(id)
     if student:
         student.delete_from_db()
     return {"message": "Student deleted"}