def details(connection, details_id, related):
    post = post_query(connection, details_id)
    if post is None:
        raise Exception("no post with id = " + details_id)

    if "user" in related:
        post["user"] = user.details(connection, post["user"])
    if "forum" in related:
        post["forum"] = forum.details(connection, post["forum"], [])
    if "thread" in related:
        post["thread"] = thread.details(connection, post["thread"], [])

    return post
def posts_list(connection, entity, params, identifier, related=[]):
    query = (
        "SELECT date, dislikes, forum, id, isApproved, isDeleted, isEdited, isHighlighted, isSpam, likes, message, "
        "parent, points, thread, user FROM post WHERE " + entity + " = " + "'" + str("".join(identifier)) + "'"
    )

    parameters = tuple()
    if "since" in params:
        query += " AND date >= %s"
        parameters += tuple(params["since"])

    query += " ORDER BY date " + "".join(params["order"])

    if "limit" in params:
        query += " LIMIT " + "".join(params["limit"])

    parameters += tuple("")
    query_res = dbConnector.select_query(connection, query, parameters)

    post_list = []
    for post in query_res:
        responseDict = {
            "date": str(post[0]),
            "dislikes": post[1],
            "forum": post[2],
            "id": post[3],
            "isApproved": bool(post[4]),
            "isDeleted": bool(post[5]),
            "isEdited": bool(post[6]),
            "isHighlighted": bool(post[7]),
            "isSpam": bool(post[8]),
            "likes": post[9],
            "message": post[10],
            "parent": post[11],
            "points": post[12],
            "thread": post[13],
            "user": post[14],
        }
        if "user" in related:
            responseDict["user"] = user.details(connection, responseDict["user"])
        if "forum" in related:
            responseDict["forum"] = forum.details(connection, short_name=responseDict["forum"], related=[])
        if "thread" in related:
            responseDict["thread"] = thread.details(connection, id=responseDict["thread"], related=[])
        post_list.append(responseDict)
    return post_list
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})