def forum_posts(connect): cursor = connect.cursor(cursor_class=MySQLCursorDict) req_args = ['forum'] opt_args = ['since', 'limit', 'sort', 'order'] short_name = extract_req(request.args, req_args) since, limit, sort, order = extract_opt(request.args, opt_args) related = extract_list(request.args, 'related', ['user', 'forum', 'thread']) forum = get_forum_by_slug(cursor, short_name) posts = get_forum_posts(cursor, short_name, since, limit, sort, order) for post in posts: if 'user' in related: post['user'] = get_user_by_email(cursor, post['user']) if 'forum' in related: post.update({'forum': forum}) if 'thread' in related: post['thread'] = get_thread_by_id(cursor, post['thread']) cursor.close() return response_ok(posts)
def thread_vote(connect): cursor = connect.cursor(cursor_class=MySQLCursorDict) req_args = ['vote', 'thread'] vote, thread = extract_req(request.get_json(force=True), req_args) set_thread_vote(cursor, thread, vote) connect.commit() thread = get_thread_by_id(cursor, thread) cursor.close() return response_ok(thread)
def thread_update(connect): cursor = connect.cursor(cursor_class=MySQLCursorDict) req_args = ['message', 'slug', 'thread'] message, slug, thread = extract_req(request.get_json(force=True), req_args) set_thread_message_slug(cursor, thread, message, slug) connect.commit() thread = get_thread_by_id(cursor, thread) cursor.close() return response_ok(thread)
def thread_details(connect): cursor = connect.cursor(cursor_class=MySQLCursorDict) req_args = ['thread'] thread = extract_req(request.args, req_args) related = extract_list(request.args, 'related', ['user', 'forum']) thread = get_thread_by_id(cursor, thread) if 'user' in related: thread['user'] = get_user_by_email(cursor, thread['user']) if 'forum' in related: thread['forum'] = get_forum_by_slug(cursor, thread['forum']) cursor.close() return response_ok(thread)
def post_details(connect): cursor = connect.cursor(cursor_class=MySQLCursorDict) req_args = ['post'] post = extract_req(request.args, req_args) related = extract_list(request.args, 'related', ['user', 'forum', 'thread']) post = get_post_by_id(cursor, post) if 'user' in related: post['user'] = get_user_by_email(cursor, post['user']) if 'forum' in related: post['forum'] = get_forum_by_slug(cursor, post['forum']) if 'thread' in related: post['thread'] = get_thread_by_id(cursor, post['thread']) cursor.close() return response_ok(post)