2024-03-05 00:17:02 +01:00
|
|
|
use chrono::{DateTime, Local, NaiveDateTime, TimeZone};
|
2023-10-29 17:31:07 +01:00
|
|
|
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<Self> {
|
|
|
|
sqlx::query_as!(
|
|
|
|
Log,
|
|
|
|
"
|
|
|
|
SELECT id, user_id, message, read_at, category
|
|
|
|
FROM notification
|
|
|
|
WHERE user_id = {}
|
|
|
|
",
|
|
|
|
user.id
|
|
|
|
)
|
|
|
|
.fetch_all(db)
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
}
|