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() + } +}