def post_list(): con = dbConnector.connect() content = helpers.json_from_get(request) try: identifier = content["forum"] entity = "forum" except KeyError: try: identifier = content["thread"] entity = "thread" except Exception as e: con.close() return json.dumps({ "code": 1, "response": (e.message)}) optional = helpers.get_optional_params(request=content, values=["limit", "order", "since"]) try: p_list = post.posts_list(con=con, entity=entity, params=optional, identifier=identifier, related=[]) except Exception as e: con.close() return json.dumps({ "code": 1, "response": (e.message)}) con.close() return json.dumps({ "code": 0, "response": p_list})
def user_listFollowers(): con = dbConnector.connect() params = helpers.json_from_get(request) optional = helpers.get_optional_params(params, ["limit", "order", "since_id"]) try: helpers.check_params(params, ["user"]) response = user.listFollowers(con, params["user"], optional) except Exception as e: con.close() return json.dumps({"code": 1, "response": (e.message)}) con.close() return json.dumps({"code": 0, "response": response})
def user_listPosts(): con = dbConnector.connect() params = helpers.json_from_get(request) optional = helpers.get_optional_params(params, ["limit", "order", "since"]) try: helpers.check_params(params, ["user"]) response = post.posts_list(con=con, entity="user", params=optional, identifier=params["user"], related=[]) except Exception as e: con.close() return json.dumps({"code": 1, "response": (e.message)}) con.close() return json.dumps({"code": 0, "response": response})
def create_user(): con = dbConnector.connect() params = request.json optional = helpers.get_optional_params(params, values=["isAnonymous"]) try: helpers.check_params(params, ["username", "about", "name", "email"]) userr = user.create(con, params["username"], params["about"], params["name"], params["email"], optional) except Exception as e: if e.message == "5": con.close(); return json.dumps({"code": 5, "response": (e.message)}) con.close() return json.dumps({"code": 1, "response": (e.message)}) con.close() return json.dumps({"code": 0, "response": userr})
def list_thread(): con = dbConnector.connect() params = helpers.json_from_get(request) optional = helpers.get_optional_params(request=params, values=["since", "limit", "order"]) try: response = thread.list(con=con, required=params, optional=optional, related=[]) except Exception as e: con.close() return json.dumps({ "code": 1, "response": (e.message)}) con.close() return json.dumps({ "code": 0, "response": response}) return
def create_thread(): con = dbConnector.connect(); params = request.json optional = helpers.get_optional_params(params, ["isDeleted"]) try: helpers.check_params(params, ["forum", "title", "isClosed", "user", "date", "message", "slug"]) response = thread.create(con, params["forum"], params["title"], params["isClosed"], params["user"], params["date"], params["message"], params["slug"], optional); except Exception as e: con.close(); return json.dumps({ "code": 3, "response": (e.message)}) con.close(); return json.dumps({ "code": 0, "response": response});
def post_create(): con = dbConnector.connect() params = request.json optional = helpers.get_optional_params( params, ["parent", "isApproved", "isHighlighted", "isEdited", "isSpam", "isDeleted"] ) try: helpers.check_params( params, ["date", "thread", "message", "user", "forum"] ) response = post.create(con, params["date"], params["thread"], params["message"], params["user"], params["forum"], optional) except Exception as e: con.close() return json.dumps({ "code": 3, "response": (e.message)}) con.close() return json.dumps({ "code": 0, "response": response})