Example #1
0
def api_author_posts(author_name):
    posts = Post.get_posts_by_author_name(author_name)
    posts = map(lambda post: dump_post(post), posts)
    posts = list(posts)
    return ok({
        'author_name': author_name,
        'posts': posts,
    })
Example #2
0
def posts_new():
    json_data = request.get_json()
    user_id = current_user.id
    author_name = json_data.get('author')
    category = json_data.get('category')
    title = json_data.get('title')
    content = json_data.get('content')

    if not all((author_name, category, title, content)):
        return error('没有提供所有参数')

    post = Post.create_post(user_id=user_id,
                            author_name=author_name,
                            category=category,
                            title=title,
                            content=content)
    return ok(dump_post(post, mode='only_id'))
Example #3
0
def posts_new():
    json_data = request.get_json()
    user_id = current_user.id
    author_name = json_data.get('author')
    category = json_data.get('category')
    title = json_data.get('title')
    content = json_data.get('content')

    if not all((author_name, category, title, content)):
        return error('没有提供所有参数')

    post = Post.create_post(
        user_id=user_id,
        author_name=author_name,
        category=category,
        title=title,
        content=content)
    return ok(dump_post(post, mode='only_id'))
Example #4
0
def posts_id(id):
    try:
        post = Post.get(id=id)
    except Post.DoesNotExist:
        return error('post does not exist', 404)
    return ok(dump_post(post))
Example #5
0
def posts_id(id):
    try:
        post = Post.get(id=id)
    except Post.DoesNotExist:
        return error('post does not exist', 404)
    return ok(dump_post(post))