Ejemplo n.º 1
0
def updateThread(request):
    if request.method == "POST":
        requestData = json.loads(request.body)
        requiredData = ["thread", "slug", "message"]
        try:
            tryParam(input=requestData, required=requiredData)
            threads = ThreadsHelper.updateThreadHelper(id=requestData["thread"], slug=requestData["slug"], message=requestData["message"])
        except Exception as e:
            return generateError(e.message)
        return getResponse(threads)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 2
0
def unfollowUser(request):
    if request.method == "POST":
        requestData = json.loads(request.body)
        requiredData = ["follower", "followee"]
        try:
            tryParam(input=requestData, required=requiredData)
            following = unfollowHelper(email1=requestData["follower"], email2=requestData["followee"])
        except Exception as e:
            return generateError(e.message)
        return getResponse(following)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 3
0
def updatePost(request):
    if request.method == "POST":
        requestData = json.loads(request.body)
        requiredData = ["user", "name", "about"]
        try:
            tryParam(input=requestData, required=requiredData)
            users = UsersHelper.updateProfileHelper(email=requestData["user"], name=requestData["name"], about=requestData["about"])
        except Exception as e:
            return generateError(e.message)
        return getResponse(users)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 4
0
def detailsUser(request):
    if request.method == "GET":
        requestData = getParam(request)
        requiredData = ["user"]
        try:
            tryParam(input=requestData, required=requiredData)
            userdetails = UsersHelper.detailsHelper(email=requestData["user"])
        except Exception as e:
            return generateError(e.message)
        return getResponse(userdetails)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 5
0
def unsubscribeThread(request):
    if request.method == "POST":
        requestData = json.loads(request.body)
        requiredData = ["thread", "user"]
        try:
            tryParam(input=requestData, required=requiredData)
            subscriptions = removeSubscriprionHelper(email=requestData["user"], thread_id=requestData["thread"])
        except Exception as e:
            return generateError(e.message)
        return getResponse(subscriptions)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 6
0
def closeThread(request):
    if request.method == "POST":
        requestData = json.loads(request.body)
        requiredData = ["thread"]
        try:
            tryParam(input=requestData, required=requiredData)
            threads = ThreadsHelper.toggleThreadHelper(id=requestData["thread"], isClosed=1)
        except Exception as e:
            return generateError(e.message)
        return getResponse(threads)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 7
0
def updatePost(request):
    if request.method == "POST":
        requestData = json.loads(request.body)
        requiredData = ["post", "message"]
        try:
            tryParam(input=requestData, required=requiredData)
            posts = PostHelpers.updatePostHelper(id=requestData["post"], message=requestData["message"])
        except Exception as e:
            return generateError(e.message)
        return getResponse(posts)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 8
0
def restorePost(request):
    if request.method == "POST":
        requiredData = ["post"]
        requestData = json.loads(request.body)
        try:
            tryParam(input=requestData, required=requiredData)
            post = PostHelpers.togglePostHelper(post_id=requestData["post"], mark=0)
        except Exception as e:
            return generateError(e.message)
        return getResponse(post)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 9
0
def listFollowing(request):
    if request.method == "GET":
        requestData = getParam(request)
        requiredData = ["user"]
        param = getOptional(request=requestData, values=["limit", "order", "since_id"])
        try:
            tryParam(input=requestData, required=requiredData)
            followings = listFollowersHelper(email=requestData["user"], fol1="followee", optional=param)
        except Exception as e:
            return generateError(e.message)
        return getResponse(followings)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 10
0
def listPost(request):
    if request.method == "GET":
        requestData = getParam(request)
        requiredData = ["user"]
        option = getOptional(request=requestData, values=["limit", "order", "since"])
        try:
            tryParam(input=requestData, required=requiredData)
            arrayPosts = PostHelpers.postListHelper(table="user", id=requestData["user"], related=[], option=option)
        except Exception as e:
            return generateError(e.message)
        return getResponse(arrayPosts)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 11
0
def detailsThread(request):
    if request.method == "GET":
        requestData = getParam(request)
        requiredData = ["thread"]
        related = getRelated(requestData)
        try:
            tryParam(input=requestData, required=requiredData)
            threads = ThreadsHelper.detailsThreadHelper(id=requestData["thread"], related=related)
        except Exception as e:
            return generateError(e.message)
        return getResponse(threads)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 12
0
def listUsersForum(request):
    if request.method == "GET":
        request_data = getParam(request)
        required_data = ["forum"]
        optional = getOptional(request=request_data, values=["limit", "order", "since_id"])
        try:
            tryParam(input=request_data, required=required_data)
            arrayUsers = ForumsHelper.listForumUsersHelper(request_data["forum"], optional)
        except Exception as e:
            return generateError(e.message)
        return getResponse(arrayUsers)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 13
0
def detailForum(request):
    if request.method == "GET":
        requestData = getParam(request)
        requiredData = ["forum"]
        related = getRelated(requestData)
        try:
            tryParam(input=requestData, required=requiredData)
            forums = ForumsHelper.detailForumHelper(short_name=requestData["forum"], related=related)
        except Exception as e:
            return generateError(e.message)
        return getResponse(forums)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 14
0
def createForum(request):
    if request.method == "POST":
        requiredData = ["name", "short_name", "user"]
        requestData = json.loads(request.body)
        try:
            tryParam(input=requestData, required=requiredData)
            forum = ForumsHelper.createForumHelper(name=requestData["name"], short_name=requestData["short_name"],
                                      user=requestData["user"])
        except Exception as e:
            print(e.message)
            return generateError(e.message)
        return getResponse(forum)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 15
0
def detailsPost(request):
    if request.method == "GET":

        requestData = getParam(request)
        requiredData = ["post"]
        relating = getRelated(requestData)
        try:
            tryParam(input=requestData, required=requiredData)
            posts = PostHelpers.detailsPostHelper(requestData["post"], option=relating)
        except Exception as e:
            return generateError(e.message)
        return getResponse(posts)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 16
0
def createUser(request):
    if request.method == "POST":

        requestData = json.loads(request.body)
        requiredData = ["email", "username", "name", "about"]
        option = getOptional(request=requestData, values=["isAnonymous"])
        try:
            tryParam(input=requestData, required=requiredData)
            users = UsersHelper.createUserHelper(email=requestData["email"], username=requestData["username"],
                               about=requestData["about"], name=requestData["name"], optional=option)
        except Exception as e:
            return generateError(e.message)
        return getResponse(users)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 17
0
def listThreadsForum(request):
    if request.method == "GET":
        required = ["forum"]
        request = getParam(request)
        related = getRelated(request)
        optional = getOptional(request=request, values=["limit", "order", "since"])
        try:
            tryParam(input=request, required=required)
            arrayThreads = ThreadsHelper.listThreadHelper(table="forum", id=request["forum"],
                                             related=related, params=optional)
        except Exception as e:
            return generateError(e.message)
        return getResponse(arrayThreads)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 18
0
def createThread(request):
    if request.method == "POST":

        requestData = json.loads(request.body)
        requiredData = ["forum", "title", "isClosed", "user", "date", "message", "slug"]
        option = getOptional(request=requestData, values=["isDeleted"])
        try:
            tryParam(input=requestData, required=requiredData)
            threads = ThreadsHelper.createThreadHelper(forum=requestData["forum"], title=requestData["title"], isClosed=requestData["isClosed"],
                                     user=requestData["user"], date=requestData["date"], message=requestData["message"],
                                     slug=requestData["slug"], optional=option)
        except Exception as e:
            return generateError(e.message)
        return getResponse(threads)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 19
0
def createPost(request):
    if request.method == "POST":
        requestData = json.loads(request.body)
        requiredData = ["user", "forum", "thread", "message", "date"]
        optionalData = ["parent", "isApproved", "isHighlighted", "isEdited", "isSpam", "isDeleted"]
        option = getOptional(request=requestData, values=optionalData)
        try:
            tryParam(input=requestData, required=requiredData)
            post = PostHelpers.createPostHelper(date=requestData["date"], thread=requestData["thread"],
                                message=requestData["message"], user=requestData["user"],
                                forum=requestData["forum"], optional=option)
        except Exception as e:
            return generateError(e.message)
        return getResponse(post)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 20
0
def thread_list(request):
    if request.method == "GET":
        requestData = getParam(request)
        id = None
        try:
            id = requestData["forum"]
            table = "forum"
        except KeyError:
            try:
                id = requestData["user"]
                table = "user"
            except KeyError:
                return generateError("No user or forum parameters setted")
        optional = getOptional(request=requestData, values=["limit", "order", "since"])
        try:
            t_list = ThreadsHelper.listThreadHelper(table=table, id=id, related=[], params=optional)
        except Exception as e:
            return generateError(e.message)
        return getResponse(t_list)
    else:
        return HttpResponse(status=400)
Ejemplo n.º 21
0
def listPost(request):
    if request.method == "GET":
        requestData = getParam(request)
        id = None
        try:
            id = requestData["forum"]
            table = "forum"
        except KeyError:
            try:
                id = requestData["thread"]
                table = "thread"
            except KeyError:
                return generateError("ListPost Error")

        optional = getOptional(request=requestData, values=["limit", "order", "since"])
        try:
            postArray = PostHelpers.postListHelper(table=table, id=id, related=[], option=optional)
        except Exception as e:
            return generateError(e.message)
        return getResponse(postArray)
    else:
        return HttpResponse(status=400)