def forum_details():
    connection = dbConnector.connect()
    params = functions.get_json(request)
    try:
        functions.check(params, ["forum"])
        response = forum.details(
            connection, params["forum"], functions.get_related(params))
    except Exception, e:
        connection.close()
        return json.dumps({"code": 3, "response": e.message})
def forum_list_threads():
    connection = dbConnector.connect()
    params = functions.get_json(request)
    optional = functions.get_optional(params, ["since", "limit", "order"])
    related = functions.get_related(params)
    try:
        functions.check(params, ["forum"])
        response = thread.list(connection=connection, optional=optional,
                               required=params, related=related)
    except Exception, e:
        connection.close()
        return json.dumps({"code": 3, "response": e.message})
def post_details():
    connection = dbConnector.connect()
    params = functions.get_json(request)
    required_data = ["post"]
    related = functions.get_related(params)
    try:
        functions.check(params, required_data)
        response = post.details(connection, params["post"], related)
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})
    connection.close()
    return json.dumps({"code": 0, "response": response})
def forum_list_posts():
    connection = dbConnector.connect()
    params = functions.get_json(request)
    optional = functions.get_optional(
        params,
        ["since",
         "limit",
         "order"]
    )
    related = functions.get_related(params)
    try:
        functions.check(params, ["forum"])
        response = post.posts_list(connection, entity="forum", params=optional, identifier=params[
                                   "forum"], related=related)
    except Exception, e:
        connection.close()
        return json.dumps({"code": 3, "response": e.message})
def details_thread():

    connection = dbConnector.connect()
    params = functions.get_json(request)
    required_data = ["thread"]
    related = functions.get_related(params)

    if 'thread' in related:
        connection.close()
        return json.dumps({"code": 3, "response": "error"})
    try:
        functions.check(params, required_data)
        response = thread.details(connection, params["thread"], related)
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})
    connection.close()
    return json.dumps({"code": 0, "response": response})