Display recent articles on the homepage

This commit is contained in:
Bat
2018-05-12 13:56:38 +01:00
parent a74215ef07
commit 397d25e431
3 changed files with 31 additions and 3 deletions
+7
View File
@@ -70,6 +70,13 @@ impl Post {
.into_iter().nth(0)
}
pub fn get_recents(conn: &PgConnection, limit: i64) -> Vec<Post> {
posts::table.order(posts::creation_date.desc())
.limit(limit)
.load::<Post>(conn)
.expect("Error loading recent posts")
}
pub fn get_authors(&self, conn: &PgConnection) -> Vec<User> {
use schema::users;
use schema::post_authors;