Compare commits

...

3 Commits

Author SHA1 Message Date
5dcd7bc745 Merge pull request 'proper-time-in-notificatoins' (#453) from proper-time-in-notificatoins into main
All checks were successful
CI/CD Pipeline / test (push) Successful in 7m56s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Successful in 5m20s
Reviewed-on: #453
2024-04-29 09:18:58 +02:00
08fe779403 remove debug println
All checks were successful
CI/CD Pipeline / test (push) Successful in 8m40s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2024-04-29 08:48:43 +02:00
9ca510b892 show proper time in notifications
Some checks failed
CI/CD Pipeline / deploy-staging (push) Blocked by required conditions
CI/CD Pipeline / deploy-main (push) Blocked by required conditions
CI/CD Pipeline / test (push) Has been cancelled
2024-04-29 08:48:15 +02:00
2 changed files with 22 additions and 6 deletions

View File

@ -70,23 +70,39 @@ 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();
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) {

View File

@ -30,7 +30,7 @@
<div class="relative flex justify-between items-center p-3">
<div class="grow me-4">
<small class="uppercase text-gray-600 dark:text-gray-100">
<strong>{{ notification.category }}</strong> &bullet; {{ notification.created_at | date(timezone="Europe/Vienna", format="%d.%m.%Y %H:%M",) }}
<strong>{{ notification.category }}</strong> &bullet; {{ notification.created_at | date(format="%d.%m.%Y %H:%M",) }}
</small>
<div class="mt-1">{{ notification.message | safe }}</div>
</div>
@ -55,7 +55,7 @@
{% if notification.read_at %}
<div class="p-3 relative">
<small class="uppercase text-gray-600 dark:text-gray-100">
<strong>{{ notification.category }}</strong> &bullet; {{ notification.created_at | date(timezone="Europe/Vienna", format="%d.%m.%Y %H:%M") }}
<strong>{{ notification.category }}</strong> &bullet; {{ notification.created_at | date(format="%d.%m.%Y %H:%M") }}
</small>
<div class="mt-1">{{ notification.message | safe }}</div>
</div>