forked from Ruderverein-Donau-Linz/rowt
add first draft of notifications
This commit is contained in:
parent
dcb7bc4c24
commit
9497116265
36
src/model/notification.rs
Normal file
36
src/model/notification.rs
Normal file
@ -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<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()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user