Add pagination to the blog page

No UI to control it yet
This commit is contained in:
Bat
2018-07-20 18:42:35 +02:00
parent 3764e295b8
commit 67eb41add1
5 changed files with 62 additions and 8 deletions
+9
View File
@@ -91,6 +91,15 @@ impl Post {
.expect("Error loading recent posts for blog")
}
pub fn blog_page(conn: &PgConnection, blog: &Blog, (min, max): (i32, i32)) -> Vec<Post> {
posts::table.filter(posts::blog_id.eq(blog.id))
.order(posts::creation_date.desc())
.offset(min.into())
.limit((max - min).into())
.load::<Post>(conn)
.expect("Error loading a page of posts for blog")
}
pub fn get_authors(&self, conn: &PgConnection) -> Vec<User> {
use schema::users;
use schema::post_authors;