Ejemplo n.º 1
0
def modify_list():
    j = request.get_json()
    c = DatabaseConnection()

    auth = check_auth(j, c)
    if auth:
        return auth

    listid = j.get("listid", None)
    if not listid:
        return {"err": "listid must not be empty"}, 400

    l = c.get_list(listid)
    if not l:
        return {"err": "list does not exist"}, 409
    u = c.get_user(j["username"])

    if l["userid"] != u["id"]:
        return {"err": "list does not belong to user"}, 400

    if request.path == "/api/deletelist":
        print("deleting list")
        c.delete_list(listid)
        return {"msg": "successfully deleted list"}, 200

    elif request.path == "/api/updatelist":
        label = j.get("label", "")
        if not label:
            return {"err": "label must not be empty"}, 400
        if not c.update_list(listid, label):
            return {"err": "attempted to give list duplicate name"}, 409
        return {"msg": "successfully updated list"}, 200

    return {"err": "invalid method used"}, 405