From 9ca510b8925ff497473fc840f591e2def138f5fb Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 29 Apr 2024 08:48:15 +0200 Subject: [PATCH 1/2] show proper time in notifications --- src/model/notification.rs | 26 ++++++++++++++++++++++---- templates/index.html.tera | 4 ++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/model/notification.rs b/src/model/notification.rs index 4678eb4..1ec7217 100644 --- a/src/model/notification.rs +++ b/src/model/notification.rs @@ -70,23 +70,41 @@ impl Notification { } pub async fn for_user(db: &SqlitePool, user: &User) -> Vec { - 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) { diff --git a/templates/index.html.tera b/templates/index.html.tera index b200554..f863cf8 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -30,7 +30,7 @@
- {{ notification.category }} • {{ notification.created_at | date(timezone="Europe/Vienna", format="%d.%m.%Y %H:%M",) }} + {{ notification.category }} • {{ notification.created_at | date(format="%d.%m.%Y %H:%M",) }}
{{ notification.message | safe }}
@@ -55,7 +55,7 @@ {% if notification.read_at %}
- {{ notification.category }} • {{ notification.created_at | date(timezone="Europe/Vienna", format="%d.%m.%Y %H:%M") }} + {{ notification.category }} • {{ notification.created_at | date(format="%d.%m.%Y %H:%M") }}
{{ notification.message | safe }}
-- 2.45.2 From 08fe779403b240aec08a2dd79581607829711d45 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 29 Apr 2024 08:48:43 +0200 Subject: [PATCH 2/2] remove debug println --- src/model/notification.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/model/notification.rs b/src/model/notification.rs index 1ec7217..a7747b7 100644 --- a/src/model/notification.rs +++ b/src/model/notification.rs @@ -88,8 +88,6 @@ ORDER BY read_at DESC, created_at DESC; .await .unwrap(); - println!("{rows:#?}"); - rows.into_iter() .map(|rec| Notification { id: rec.id, -- 2.45.2