Display notifications

This commit is contained in:
Bat
2018-05-13 14:35:55 +01:00
parent 726c2c7e82
commit b91f567777
5 changed files with 43 additions and 1 deletions
+8 -1
View File
@@ -1,8 +1,9 @@
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
use models::users::User;
use schema::notifications;
#[derive(Queryable, Identifiable)]
#[derive(Queryable, Identifiable, Serialize)]
pub struct Notification {
pub id: i32,
pub title: String,
@@ -35,4 +36,10 @@ impl Notification {
.expect("Couldn't load notification by ID")
.into_iter().nth(0)
}
pub fn find_for_user(conn: &PgConnection, user: &User) -> Vec<Notification> {
notifications::table.filter(notifications::user_id.eq(user.id))
.load::<Notification>(conn)
.expect("Couldn't load user notifications")
}
}