Order notifications by creation date

This commit is contained in:
Bat
2018-05-24 11:12:27 +01:00
parent daf9120fba
commit a0b4a6eacb
4 changed files with 9 additions and 1 deletions
+4 -1
View File
@@ -1,3 +1,4 @@
use chrono::NaiveDateTime;
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
use models::users::User;
@@ -9,7 +10,8 @@ pub struct Notification {
pub title: String,
pub content: Option<String>,
pub link: Option<String>,
pub user_id: i32
pub user_id: i32,
pub creation_date: NaiveDateTime
}
#[derive(Insertable)]
@@ -39,6 +41,7 @@ impl Notification {
pub fn find_for_user(conn: &PgConnection, user: &User) -> Vec<Notification> {
notifications::table.filter(notifications::user_id.eq(user.id))
.order_by(notifications::creation_date.desc())
.load::<Notification>(conn)
.expect("Couldn't load user notifications")
}