From 94971162654c08ce8fece70ffd523a740b08fd84 Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 29 Oct 2023 17:31:07 +0100 Subject: [PATCH] add first draft of notifications --- src/model/notification.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/model/notification.rs diff --git a/src/model/notification.rs b/src/model/notification.rs new file mode 100644 index 0000000..d345f74 --- /dev/null +++ b/src/model/notification.rs @@ -0,0 +1,36 @@ +use chrono::{DateTime, Local, NaiveDateTime, TimeZone, Utc}; +use serde::{Deserialize, Serialize}; +use sqlx::{FromRow, SqlitePool}; + +#[derive(FromRow, Debug, Serialize, Deserialize)] +pub struct Notification { + pub id: i64, + pub user_id: i64, + pub message: String, + pub read_at: NaiveDateTime, + pub category: String, +} + +impl Notification { + //pub async fn create(db: &SqlitePool, msg: String) -> bool { + // sqlx::query!("INSERT INTO log(msg) VALUES (?)", msg,) + // .execute(db) + // .await + // .is_ok() + //} + + async fn for_user(db: &SqlitePool, user: &User) -> Vec { + sqlx::query_as!( + Log, + " +SELECT id, user_id, message, read_at, category +FROM notification +WHERE user_id = {} + ", + user.id + ) + .fetch_all(db) + .await + .unwrap() + } +}