notifications
This commit is contained in:
parent
c9e163c92c
commit
ab64583efc
@ -8,25 +8,35 @@ pub struct Notification {
|
|||||||
pub user_id: i64,
|
pub user_id: i64,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub read_at: NaiveDateTime,
|
pub read_at: NaiveDateTime,
|
||||||
|
pub created_at: NaiveDateTime,
|
||||||
pub category: String,
|
pub category: String,
|
||||||
|
pub link: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Notification {
|
impl Notification {
|
||||||
//pub async fn create(db: &SqlitePool, msg: String) -> bool {
|
pub async fn create(
|
||||||
// sqlx::query!("INSERT INTO log(msg) VALUES (?)", msg,)
|
db: &SqlitePool,
|
||||||
// .execute(db)
|
user: &User,
|
||||||
// .await
|
message: &str,
|
||||||
// .is_ok()
|
category: &str,
|
||||||
//}
|
link: Option<&str>,
|
||||||
|
) {
|
||||||
|
sqlx::query!(
|
||||||
|
"INSERT INTO notification(user_id, message, category, link) VALUES (?, ?, ?, ?)",
|
||||||
|
user.id,
|
||||||
|
message,
|
||||||
|
category,
|
||||||
|
link
|
||||||
|
)
|
||||||
|
.execute(db)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
async fn for_user(db: &SqlitePool, user: &User) -> Vec<Self> {
|
async fn for_user(db: &SqlitePool, user: &User) -> Vec<Self> {
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
Log,
|
Log,
|
||||||
"
|
"SELECT * FROM notification WHERE user_id = {}",
|
||||||
SELECT id, user_id, message, read_at, category
|
|
||||||
FROM notification
|
|
||||||
WHERE user_id = {}
|
|
||||||
",
|
|
||||||
user.id
|
user.id
|
||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(db)
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS "notification" (
|
||||||
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"user_id" INTEGER NOT NULL REFERENCES user(id),
|
||||||
|
"message" TEXT NOT NULL,
|
||||||
|
"read_at" DATETIME,
|
||||||
|
"created_at" DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"category" TEXT NOT NULL,
|
||||||
|
"link" TEXT
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user