show proper time in notifications
This commit is contained in:
@ -70,23 +70,41 @@ impl Notification {
|
||||
}
|
||||
|
||||
pub async fn for_user(db: &SqlitePool, user: &User) -> Vec<Self> {
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
let rows = sqlx::query!(
|
||||
"
|
||||
SELECT * FROM notification
|
||||
SELECT id, user_id, message, read_at, datetime(created_at, 'localtime') as created_at, category, link FROM notification
|
||||
WHERE
|
||||
user_id = ?
|
||||
AND (
|
||||
read_at IS NULL
|
||||
OR read_at >= datetime('now', '-14 days')
|
||||
)
|
||||
AND created_at is not NULL
|
||||
ORDER BY read_at DESC, created_at DESC;
|
||||
",
|
||||
user.id
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
println!("{rows:#?}");
|
||||
|
||||
rows.into_iter()
|
||||
.map(|rec| Notification {
|
||||
id: rec.id,
|
||||
user_id: rec.user_id,
|
||||
message: rec.message,
|
||||
read_at: rec.read_at,
|
||||
created_at: NaiveDateTime::parse_from_str(
|
||||
&rec.created_at.unwrap(),
|
||||
"%Y-%m-%d %H:%M:%S",
|
||||
)
|
||||
.unwrap(),
|
||||
category: rec.category,
|
||||
link: rec.link,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub async fn mark_read(self, db: &SqlitePool) {
|
||||
|
Reference in New Issue
Block a user