Beispiel #1
0
def createForum():

    obj = objectBase.deserializeObject(request.json, forum)
    obj.creator = basic_auth.username

    isPassed = appUtility.ifExistDoError(dbPath, obj, ["name"], httpUtility.Conflict)
    if not isPassed:
        return
    
    db.executeInsert(dbPath, obj)
    return make_response(obj.serializeJson(), httpUtility.Created)
Beispiel #2
0
def createUser():

    obj = objectBase.deserializeObject(request.json, user)

    isPassed = appUtility.ifExistDoError(dbPath, obj, ["username"], httpUtility.Conflict)
    if not isPassed:
        return

    obj = db.executeInsert(dbPath, obj)

    response = make_response("", httpUtility.Created)

    return response
Beispiel #3
0
def changeUserPassword(username):

    obj = objectBase.deserializeObject(request.json, user)
    obj.username = username

    isPassed = appUtility.ifNotExistDoError(dbPath, obj, ["username"], httpUtility.NotFound)
    if not isPassed:
        return

    if obj.username != basic_auth.username:
        abort(httpUtility.Conflict)

    obj = db.executeUpdate(dbPath, obj, ["username"])

    response = make_response("", httpUtility.Ok)

    return response
Beispiel #4
0
def createThread(forum_id):

    obj = objectBase.deserializeObject(request.json, threadConversation)
    obj.forum_id = forum_id
    obj.author = basic_auth.username
    obj.timestamp = datetime.datetime.now()

    isPassed = appUtility.ifNotExistDoError(dbPath, obj, ["forum_id"], httpUtility.NotFound)
    if not isPassed:
        return

    obj = db.executeInsert(dbPath, obj)

    response = make_response(obj.serializeJson(), httpUtility.Created)

    response.headers["Location"] = "{url}/{forum_id}/{thread_id}".format(url=forumsUrl, forum_id=obj.forum_id, thread_id=obj.id)

    return response
Beispiel #5
0
def createPost(forum_id, thread_id):

    checkObj = threadConversation()
    checkObj.id = thread_id
    checkObj.forum_id = forum_id

    isPassed = appUtility.ifNotExistDoError(dbPath, checkObj, ["id", "forum_id"], httpUtility.NotFound)
    if not isPassed:
        return

    obj = objectBase.deserializeObject(request.json, post)
    obj.thread_id = thread_id
    obj.poster = basic_auth.username
    obj.timestamp = datetime.datetime.now()
    obj = db.executeInsert(dbPath, obj)

    response = make_response(obj.serializeJson(), httpUtility.Created)

    return response