Esempio n. 1
0
def creatClassWork():
    workData = []

    # kalau file users-file.json udah ada, di read dulu. kalau file ga ada, ga usah di read, langsung write
    workData = readFile(classworkFileLocation)
    body = request.json

    response = {}
    response["message"] = "Creat classwork SUKSES"
    response["data"] = {}

    classworkAlreadyExist = False
    for work in workData:
        if body["classworkid"] == work["classworkid"]:
            response["message"] = "Classwork ID {} is already exist".format(
                body["classworkid"])
            classworkAlreadyExist = True
            break
    if not classworkAlreadyExist:
        body["answers"] = []
        workData.append(body)

        # siapin file buat di write
        writeFile(classworkFileLocation, workData)

        # menambahkan classworkid di classwork yang ada di database classes-file
        classesData = readFile(classFileLocation)
        for class_ in classesData:
            if body["class"] == class_["classid"]:
                if body["classworkid"] not in class_["classwork"]:
                    class_["classwork"].append(body)
        writeFile(classFileLocation, classesData)

    return jsonify(response)
Esempio n. 2
0
def joinClass():
    body = request.json

    response = {}
    response["message"] = "JOIN CLASS SUKSES"
    response["data"] = {}

    # nambahin userid ke classes-file
    classesData = readFile(classFileLocation)
    usersData = readFile(userFileLocation)

    AlreadyExist = False
    for class_ in classesData:
        if body["classid"] == class_["classid"]:
            if body["userId"] in class_["students"]:
                response["message"] = "Class ID {} is already exist".format(
                    body["classid"])
                AlreadyExist = True
                break
    for user in usersData:
        if body["userId"] == user["userId"]:
            if body["classid"] in user["classes_as_student"]:
                response["message"] = "user ID {} is already exist".format(
                    body["userId"])
                AlreadyExist = True
    if not AlreadyExist:
        response["data"] = body
        class_["students"].append(body["userId"])
        user["classes_as_student"].append(body["classid"])
        writeFile(classFileLocation, classesData)
        writeFile(userFileLocation, usersData)

    return jsonify(response)
Esempio n. 3
0
def updateclasswork(id):
    workData = getAllClasswork().json
    body = request.json

    for work in workData:
        if id == work["classworkid"]:
            work["question"] = body["question"]

    writeFile(classworkFileLocation, workData)
    return "UPDATE QUESTION ANDA BERHASIL"
Esempio n. 4
0
def createClass():
    classesData = []

    body = request.json
    body["students"] = []
    body["classwork"] = []

    response = {}
    response["message"] = "Creat class SUKSES"
    response["data"] = {}

    classesData = readFile(classFileLocation)

    # check class id apakah sudah ada
    classidAlreadyExist = False
    for class_ in classesData:
        if class_["classid"] == body["classid"]:
            response["message"] = "Class ID {} is already exist".format(
                body["classid"])
            classidAlreadyExist = True
        elif class_["classname"] == body["classname"]:
            response["message"] = "Class Name {} is already exist".format(
                body["classname"])
            classidAlreadyExist = True
        elif class_["teachers"] == body["teachers"]:
            response["message"] = "Teacher {} is already exist".format(
                body["teachers"])
            classidAlreadyExist = True
            break

    if not classidAlreadyExist:
        response["data"] = body
        classesData.append(body)

        # siapin file buat di write
        writeFile(classFileLocation, classesData)

        # MENAMBAHKAN CLASSES AS TEACHER DI USER FILE
        usersTeac = readFile(userFileLocation)

        for user in usersTeac:
            if body["teachers"] == user["userId"]:
                if body["teachers"] not in user["classes_as_teacher"]:
                    user["classes_as_teacher"].append(body["classid"])

        writeFile(userFileLocation, usersTeac)

    return jsonify(response)
Esempio n. 5
0
def updateClass(id):
    class_Data = getAllClasses().json
    body = request.json

    response = {}
    response["message"] = "GAGAL UPDATE"
    response["data"] = {}

    for class_ in class_Data:
        if id == class_["classid"]:
            class_["classname"] = body["classname"]
            response["message"] = "update dengan Class ID {} berhasil".format(
                id)
            response["data"] = class_
    writeFile(classFileLocation, class_Data)
    return jsonify(response)
Esempio n. 6
0
def deleteClassWork(id):
    # siapin file buat di read
    workData = getAllClasswork().json
    class_Data = getAllClasses().json

    for work in workData:
        if id == work["classworkid"]:
            workData.remove(work)
    for kelas in class_Data:
        if id in kelas["classwork"]:
            kelas["classwork"].remove(id)

    writeFile(classworkFileLocation, workData)

    writeFile(classFileLocation, class_Data)

    return "CLASSWORK BERHASIL DI HAPUS"
Esempio n. 7
0
def updateUser(id):
    userData = getAllUsers().json
    body = request.json
    response = {}
    response["message"] = "GAGAL UPDATE"
    response["data"] = {}

    for user in userData:
        if id == user["userId"]:
            user["username"] = body["username"]
            user["fullName"] = body["fullName"]
            user["password"] = encryp(body["password"])
            user["email"] = body["email"]
            response["message"] = "update dengan ID {} berhasil".format(id)
            response["data"] = user
    writeFile(userFileLocation, userData)
    return jsonify(response)
Esempio n. 8
0
def outClass(id):
    body = request.json
    # siapin file buat di read
    userData = getAllUsers().json
    class_Data = getAllClasses().json

    for kelas in class_Data:
        if id == kelas["classid"]:
            for user in userData:
                if user["userId"] == body["userId"]:
                    user["classes_as_student"].remove(id)
                    kelas["students"].remove(user["userId"])

    writeFile(userFileLocation, userData)

    writeFile(classFileLocation, class_Data)

    return "ANDA TELAH KELUAR KELAS"
Esempio n. 9
0
def assignClassWork(id):
    body = request.json

    response = {}
    response["message"] = "Input Jawaban Sukses"
    response["data"] = {}

    # nambahin userid ke classes-file
    workData = readFile(classworkFileLocation)

    for work in workData:
        if id == work["classworkid"]:
            work["answers"].append(body)
            response["data"] = work

    writeFile(classworkFileLocation, workData)

    return jsonify(response)
Esempio n. 10
0
def deleteClass(id):
    # siapin file buat di read
    userData = getAllUsers().json
    workData = getAllClasswork().json
    class_Data = getAllClasses().json

    for kelas in class_Data:
        if id == kelas["classid"]:
            class_Data.remove(kelas)

    for work in workData:
        if id == work["class"]:
            workData.remove(work)
            break
    for user in userData:
        if id in user["classes_as_student"]:
            user["classes_as_student"].remove(id)
    for user in userData:
        if id in user["classes_as_teacher"]:
            user["classes_as_teacher"].remove(id)

    writeFile(classFileLocation, class_Data)
    writeFile(classworkFileLocation, workData)
    writeFile(userFileLocation, userData)

    return "CLASS ANDA BERHASIL DI HAPUS"
Esempio n. 11
0
def register():
    userData = []
    body = request.json
    body["classes_as_student"] = []
    body["classes_as_teacher"] = []

    response = {}
    response["message"] = "Creat class SUKSES"
    response["data"] = {}

    # kalau file users-file.json udah ada, di read dulu. kalau file ga ada, ga usah di read, langsung write
    userData = readFile(userFileLocation)

    AlreadyExist = False
    for user in userData:
        if user["userId"] == body["userId"]:
            response["message"] = "User ID {} is already exist".format(
                body["userId"])
            AlreadyExist = True
        elif user["username"] == body["username"]:
            response["message"] = "username {} is already exist".format(
                body["username"])
            AlreadyExist = True
        elif user["email"] == body["email"]:
            response["message"] = "email {} is already exist".format(
                body["email"])
            AlreadyExist = True
            break

    if not AlreadyExist:
        response["data"] = body
        body["password"] = encryp(body["password"])
        userData.append(body)

        # siapin file buat di write
        writeFile(userFileLocation, userData)

    return jsonify(response)