mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-22 19:41:03 +00:00
Order notifications by creation date
This commit is contained in:
parent
daf9120fba
commit
a0b4a6eacb
4 changed files with 9 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
-- This file should undo anything in `up.sql`
|
||||||
|
ALTER TABLE notifications DROP COLUMN creation_date;
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- Your SQL goes here
|
||||||
|
ALTER TABLE notifications ADD COLUMN creation_date TIMESTAMP NOT NULL DEFAULT now();
|
|
@ -1,3 +1,4 @@
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
|
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
|
||||||
|
|
||||||
use models::users::User;
|
use models::users::User;
|
||||||
|
@ -9,7 +10,8 @@ pub struct Notification {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub content: Option<String>,
|
pub content: Option<String>,
|
||||||
pub link: Option<String>,
|
pub link: Option<String>,
|
||||||
pub user_id: i32
|
pub user_id: i32,
|
||||||
|
pub creation_date: NaiveDateTime
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable)]
|
#[derive(Insertable)]
|
||||||
|
@ -39,6 +41,7 @@ impl Notification {
|
||||||
|
|
||||||
pub fn find_for_user(conn: &PgConnection, user: &User) -> Vec<Notification> {
|
pub fn find_for_user(conn: &PgConnection, user: &User) -> Vec<Notification> {
|
||||||
notifications::table.filter(notifications::user_id.eq(user.id))
|
notifications::table.filter(notifications::user_id.eq(user.id))
|
||||||
|
.order_by(notifications::creation_date.desc())
|
||||||
.load::<Notification>(conn)
|
.load::<Notification>(conn)
|
||||||
.expect("Couldn't load user notifications")
|
.expect("Couldn't load user notifications")
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ table! {
|
||||||
content -> Nullable<Text>,
|
content -> Nullable<Text>,
|
||||||
link -> Nullable<Varchar>,
|
link -> Nullable<Varchar>,
|
||||||
user_id -> Int4,
|
user_id -> Int4,
|
||||||
|
creation_date -> Timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue