add notes
Some checks failed
CI/CD Pipeline / deploy-staging (push) Has been cancelled
CI/CD Pipeline / test (push) Has been cancelled
CI/CD Pipeline / deploy-main (push) Has been cancelled

This commit is contained in:
2025-05-03 21:12:04 +02:00
parent e360c4f06b
commit 151c97aabc
4 changed files with 34 additions and 5 deletions

View File

@ -1,5 +1,6 @@
use std::ops::DerefMut;
use super::user::User;
use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
@ -51,4 +52,21 @@ impl Activity {
Self::create_with_tx(&mut tx, text, relevant_for, keep_until).await;
tx.commit().await.unwrap();
}
pub async fn for_user(db: &SqlitePool, user: &User) -> Vec<Activity> {
let user_str = format!("user-{};", user.id);
sqlx::query_as!(
Self,
"
SELECT id, created_at, text, relevant_for, keep_until FROM activity
WHERE
relevant_for like CONCAT('%', ?, '%')
ORDER BY created_at DESC;
",
user_str
)
.fetch_all(db)
.await
.unwrap()
}
}

View File

@ -11,11 +11,18 @@ impl User {
&self,
db: &SqlitePool,
updated_by: &ManageUserUser,
user: &User,
note: &str,
) -> Result<(), String> {
let note = note.trim();
Activity::create(db, note, "relevant_for", None).await;
Activity::create(
db,
&format!("({updated_by}) {note}"),
&format!("user-{};", user.id),
None,
)
.await;
Ok(())
}