Exemple #1
0
async def get_my_posts_api(pagination=Depends(pagination), current_user=Depends(get_current_user)):
    cursor = Post.find({'created_by': current_user.id}) \
        .sort('created_at', -1) \
        .skip(pagination['skip']) \
        .limit(pagination['limit'])

    posts = [post.dump() for post in await cursor.to_list(length=pagination['limit'])]
    return posts
Exemple #2
0
async def get_posts_api(pagination=Depends(pagination)):
    cursor = Post.find() \
        .sort('created_at', -1) \
        .skip(pagination['skip']) \
        .limit(pagination['limit'])

    posts = [post.dump() for post in await cursor.to_list(length=pagination['limit'])]
    return posts