proper-time-in-notificatoins #452
@ -70,23 +70,41 @@ impl Notification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn for_user(db: &SqlitePool, user: &User) -> Vec<Self> {
|
pub async fn for_user(db: &SqlitePool, user: &User) -> Vec<Self> {
|
||||||
sqlx::query_as!(
|
let rows = sqlx::query!(
|
||||||
Self,
|
|
||||||
"
|
"
|
||||||
SELECT * FROM notification
|
SELECT id, user_id, message, read_at, datetime(created_at, 'localtime') as created_at, category, link FROM notification
|
||||||
WHERE
|
WHERE
|
||||||
user_id = ?
|
user_id = ?
|
||||||
AND (
|
AND (
|
||||||
read_at IS NULL
|
read_at IS NULL
|
||||||
OR read_at >= datetime('now', '-14 days')
|
OR read_at >= datetime('now', '-14 days')
|
||||||
)
|
)
|
||||||
|
AND created_at is not NULL
|
||||||
ORDER BY read_at DESC, created_at DESC;
|
ORDER BY read_at DESC, created_at DESC;
|
||||||
",
|
",
|
||||||
user.id
|
user.id
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(db)
|
||||||
.await
|
.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) {
|
pub async fn mark_read(self, db: &SqlitePool) {
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<div class="relative flex justify-between items-center p-3">
|
<div class="relative flex justify-between items-center p-3">
|
||||||
<div class="grow me-4">
|
<div class="grow me-4">
|
||||||
<small class="uppercase text-gray-600 dark:text-gray-100">
|
<small class="uppercase text-gray-600 dark:text-gray-100">
|
||||||
<strong>{{ notification.category }}</strong> • {{ notification.created_at | date(timezone="Europe/Vienna", format="%d.%m.%Y %H:%M",) }}
|
<strong>{{ notification.category }}</strong> • {{ notification.created_at | date(format="%d.%m.%Y %H:%M",) }}
|
||||||
</small>
|
</small>
|
||||||
<div class="mt-1">{{ notification.message | safe }}</div>
|
<div class="mt-1">{{ notification.message | safe }}</div>
|
||||||
</div>
|
</div>
|
||||||
@ -55,7 +55,7 @@
|
|||||||
{% if notification.read_at %}
|
{% if notification.read_at %}
|
||||||
<div class="p-3 relative">
|
<div class="p-3 relative">
|
||||||
<small class="uppercase text-gray-600 dark:text-gray-100">
|
<small class="uppercase text-gray-600 dark:text-gray-100">
|
||||||
<strong>{{ notification.category }}</strong> • {{ notification.created_at | date(timezone="Europe/Vienna", format="%d.%m.%Y %H:%M") }}
|
<strong>{{ notification.category }}</strong> • {{ notification.created_at | date(format="%d.%m.%Y %H:%M") }}
|
||||||
</small>
|
</small>
|
||||||
<div class="mt-1">{{ notification.message | safe }}</div>
|
<div class="mt-1">{{ notification.message | safe }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user