コード例 #1
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)
コード例 #2
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)
コード例 #3
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)
コード例 #4
0
def getClass(id):
    response = {}
    response["message"] = "Class with classid {} is not found.".format(id)
    response["data"] = {}

    # read data di user
    userData = getAllUsers().json
    # siapin file buat di read
    classesData = readFile(classFileLocation)
    # mencari kelas dengan yang sama di classID dan mengosongkan students agar bisa di isi fullname
    classData = {}
    classFound = False
    for class_ in classesData:
        if id == class_["classid"]:
            response["data"] = class_
            response["message"] = "Get Class Success"
            classFound = True
            break
    if classFound:
        classData["students"] = []
    # mengambil fullname untuk menggantikan userId yang di tampilkan students
    for user in userData:
        if id in user["classes_as_student"]:
            class_["students"].append(user["fullName"])
    return jsonify(response)
コード例 #5
0
def getclasswork(id):
    # siapin file buat di read
    workData = readFile(classworkFileLocation)

    for work in workData:
        if id == work["classworkid"]:
            return jsonify(work)

    return "ClassWork ID {} is not found".format(id)
コード例 #6
0
def getUser(id):
    response = {}
    response["message"] = "User ID {} is not found".format(id)
    response["data"] = {}

    # siapin file buat di read
    userData = readFile(userFileLocation)
    for user in userData:
        if id == user["userId"]:
            response["message"] = "User Found"
            response["data"] = user
            break

    return jsonify(response)
コード例 #7
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)
コード例 #8
0
def login():
    response = {}
    response["message"] = "login failed. username or password SALAH"
    response["data"] = {}
    statusCode = 400

    body = request.json

    # siapin file buat di read
    userData = readFile(userFileLocation)

    for user in userData:
        if body["username"] == user["username"]:
            if body["password"] == decryp(user["password"]):
                response["message"] = "login succses, welcome {}".format(
                    user["fullName"])
                response["data"] = user
                statusCode = 200
                # response["token"] = encode(response["data"])
            break
    return jsonify(response), statusCode
コード例 #9
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)
コード例 #10
0
def getAllClasswork():
    # siapin file buat di read
    workData = readFile(classworkFileLocation)

    return jsonify(workData)
コード例 #11
0
def getAllClasses():

    # siapin file buat di read
    classesData = readFile(classFileLocation)

    return jsonify(classesData)
コード例 #12
0
def getAllUsers():
    # siapin file buat di read
    userData = readFile(userFileLocation)

    return jsonify(userData)