Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(notification_service): ability to mark notifications as undone (#466)

Will Hutchinson138b12a35ff4
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index fa1b277951..7760cd1d0a 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -5729,6 +5729,7 @@ dependencies = [
"serde",
"sqlx",
"tracing",
+ "uuid",
]
[[package]]
@@ -5781,6 +5782,7 @@ dependencies = [
"url",
"utoipa",
"utoipa-swagger-ui",
+ "uuid",
]
[[package]]
diff --git a/rust/cloud-storage/notification_db_client/.sqlx/query-69de5e91294da24e3c0c22ff7cbb156ec4433cb228a034aed09e059ef005e92e.json b/rust/cloud-storage/notification_db_client/.sqlx/query-69de5e91294da24e3c0c22ff7cbb156ec4433cb228a034aed09e059ef005e92e.json
new file mode 100644
index 0000000000..cdecd21b19
--- /dev/null
+++ b/rust/cloud-storage/notification_db_client/.sqlx/query-69de5e91294da24e3c0c22ff7cbb156ec4433cb228a034aed09e059ef005e92e.json
@@ -0,0 +1,16 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n UPDATE user_notification\n SET done = $3\n WHERE user_id = $1\n AND notification_id = ANY($2)\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Text",
+ "UuidArray",
+ "Bool"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "69de5e91294da24e3c0c22ff7cbb156ec4433cb228a034aed09e059ef005e92e"
+}
diff --git a/rust/cloud-storage/notification_db_client/.sqlx/query-89cc7986cdb59ec22495a546b8043664f1cec02173a09855cd3103058bc810ea.json b/rust/cloud-storage/notification_db_client/.sqlx/query-89cc7986cdb59ec22495a546b8043664f1cec02173a09855cd3103058bc810ea.json
deleted file mode 100644
index 92329aa36a..0000000000
--- a/rust/cloud-storage/notification_db_client/.sqlx/query-89cc7986cdb59ec22495a546b8043664f1cec02173a09855cd3103058bc810ea.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n DELETE FROM user_notification un\n WHERE un.user_id = $1\n AND un.notification_id = ANY($2)\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Text",
- "UuidArray"
- ]
- },
- "nullable": []
- },
- "hash": "89cc7986cdb59ec22495a546b8043664f1cec02173a09855cd3103058bc810ea"
-}
diff --git a/rust/cloud-storage/notification_db_client/Cargo.toml b/rust/cloud-storage/notification_db_client/Cargo.toml
index 20a7b4f678..1fff36b387 100644
--- a/rust/cloud-storage/notification_db_client/Cargo.toml
+++ b/rust/cloud-storage/notification_db_client/Cargo.toml
@@ -14,3 +14,4 @@ models_pagination = { path = "../models_pagination" }
serde = { workspace = true }
sqlx = { workspace = true }
tracing = { workspace = true }
+uuid = { workspace = true }
diff --git a/rust/cloud-storage/notification_db_client/src/channel_notification_email_sent/delete.rs b/rust/cloud-storage/notification_db_client/src/channel_notification_email_sent/delete.rs
index 6d81b4bc46..2afc755257 100644
--- a/rust/cloud-storage/notification_db_client/src/channel_notification_email_sent/delete.rs
+++ b/rust/cloud-storage/notification_db_client/src/channel_notification_email_sent/delete.rs
@@ -1,5 +1,3 @@
-use sqlx::types::Uuid;
-
/// Deletes the channel_notification_email_sent for the given channel id and user id.
#[tracing::instrument(skip(db))]
pub async fn delete_channel_notification_email_sent(
@@ -25,13 +23,8 @@ pub async fn delete_channel_notification_email_sent(
pub async fn delete_channel_notification_email_sent_by_notification_ids(
db: &sqlx::Pool<sqlx::Postgres>,
user_id: &str,
- notification_ids: &[String],
+ notification_ids: &[uuid::Uuid],
) -> anyhow::Result<()> {
- let notification_ids = notification_ids
- .iter()
- .map(|id| macro_uuid::string_to_uuid(id))
- .collect::<Result<Vec<Uuid>, _>>()?;
-
sqlx::query!(
r#"
DELETE FROM channel_notification_email_sent
@@ -41,7 +34,7 @@ pub async fn delete_channel_notification_email_sent_by_notification_ids(
AND channel_notification_email_sent.channel_id = n.event_item_id::uuid
AND channel_notification_email_sent.user_id = $2;
"#,
- &notification_ids,
+ notification_ids,
&user_id
)
.execute(db)
diff --git a/rust/cloud-storage/notification_db_client/src/user_notification/delete.rs b/rust/cloud-storage/notification_db_client/src/user_notification/delete.rs
index 7153bfecd2..d898c13ed0 100644
--- a/rust/cloud-storage/notification_db_client/src/user_notification/delete.rs
+++ b/rust/cloud-storage/notification_db_client/src/user_notification/delete.rs
@@ -1,5 +1,3 @@
-use sqlx::types::Uuid;
-
#[tracing::instrument(skip(pool))]
pub async fn delete_all_users_notification(
pool: &sqlx::PgPool,
@@ -43,12 +41,8 @@ pub async fn delete_user_notification(
pub async fn bulk_delete_user_notification(
pool: &sqlx::PgPool,
user_id: &str,
- notification_ids: &Vec<String>,
+ notification_ids: &Vec<uuid::Uuid>,
) -> anyhow::Result<()> {
- let notification_uuids = notification_ids
- .iter()
- .map(|id| macro_uuid::string_to_uuid(id))
- .collect::<Result<Vec<Uuid>, _>>()?;
sqlx::query!(
r#"
UPDATE user_notification
@@ -57,7 +51,7 @@ pub async fn bulk_delete_user_notification(
AND notification_id = ANY($2)
"#,
user_id,
- &notification_uuids,
+ &notification_ids,
)
.execute(pool)
.await?;
@@ -66,34 +60,4 @@ pub async fn bulk_delete_user_notification(
}
#[cfg(test)]
-mod tests {
- use super::*;
- use sqlx::{Pool, Postgres};
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_notifications")))]
- async fn test_delete_user_notification(pool: Pool<Postgres>) -> anyhow::Result<()> {
- delete_user_notification(
- &pool,
- "0193b1ea-a542-7589-893b-2b4a509c1e74",
- )
- .await?;
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../fixtures", scripts("user_notifications")))]
- async fn test_bulk_delete_user_notification(pool: Pool<Postgres>) -> anyhow::Result<()> {
- bulk_delete_user_notification(
- &pool,
- &vec![
- "0193b1ea-a542-7589-893b-2b4a509c1e76".to_string(),
- "0193b1ea-a542-7589-893b-2b4a509c1e75".to_string(),
- ],
- )
- .await?;
-
- Ok(())
- }
-}
+mod test;
diff --git a/rust/cloud-storage/notification_db_client/src/user_notification/delete/test.rs b/rust/cloud-storage/notification_db_client/src/user_notification/delete/test.rs
new file mode 100644
index 0000000000..45b45f9b2b
--- /dev/null
+++ b/rust/cloud-storage/notification_db_client/src/user_notification/delete/test.rs
@@ -0,0 +1,29 @@
+use super::*;
+use sqlx::{Pool, Postgres};
+
+#[sqlx::test(fixtures(path = "../../../fixtures", scripts("user_notifications")))]
+async fn test_delete_user_notification(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ delete_user_notification(
+ &pool,
+ "0193b1ea-a542-7589-893b-2b4a509c1e74",
+ )
+ .await?;
+
+ Ok(())
+}
+
+#[sqlx::test(fixtures(path = "../../../fixtures", scripts("user_notifications")))]
+async fn test_bulk_delete_user_notification(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ bulk_delete_user_notification(
+ &pool,
+ &vec![
+ macro_uuid::string_to_uuid("0193b1ea-a542-7589-893b-2b4a509c1e76")?,
+ macro_uuid::string_to_uuid("0193b1ea-a542-7589-893b-2b4a509c1e75")?,
+ ],
+ )
+ .await?;
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/notification_db_client/src/user_notification/patch/done.rs b/rust/cloud-storage/notification_db_client/src/user_notification/patch/done.rs
index c20bd0ae6c..08bb86e547 100644
--- a/rust/cloud-storage/notification_db_client/src/user_notification/patch/done.rs
+++ b/rust/cloud-storage/notification_db_client/src/user_notification/patch/done.rs
@@ -22,25 +22,24 @@ pub async fn patch_done(
Ok(())
}
-/// Marks the user's notifications as done.
+/// Marks the user's notifications as done or undone.
#[tracing::instrument(skip(db))]
pub async fn bulk_patch_done(
db: &sqlx::Pool<sqlx::Postgres>,
user_id: &str,
- notification_ids: &Vec<String>,
+ notification_ids: &Vec<uuid::Uuid>,
+ done: bool,
) -> anyhow::Result<()> {
- let notification_uuids = notification_ids
- .iter()
- .map(|id| macro_uuid::string_to_uuid(id))
- .collect::<Result<Vec<Uuid>, _>>()?;
sqlx::query!(
r#"
- DELETE FROM user_notification un
- WHERE un.user_id = $1
- AND un.notification_id = ANY($2)
+ UPDATE user_notification
+ SET done = $3
+ WHERE user_id = $1
+ AND notification_id = ANY($2)
"#,
user_id,
- &notification_uuids,
+ notification_ids,
+ done
)
.execute(db)
.await?;
@@ -76,85 +75,4 @@ pub async fn bulk_patch_done_by_event(
}
#[cfg(test)]
-mod tests {
- use super::*;
- use sqlx::{Pool, Postgres};
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("user_notifications")))]
- async fn test_patch_done(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let notification_id = "0193b1ea-a542-7589-893b-2b4a509c1e76";
- let user_id = "macro|[email protected]";
-
- patch_done(&pool, notification_id, user_id).await?;
-
- let notification: bool = sqlx::query!(
- r#"
- SELECT done as "done" FROM user_notification WHERE notification_id = $1 AND user_id = $2
- "#,
- macro_uuid::string_to_uuid(notification_id)?,
- user_id,
- )
- .map(|n| n.done)
- .fetch_one(&pool)
- .await?;
-
- assert!(notification);
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("user_notifications")))]
- async fn test_bulk_patch_done(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let user_id = "macro|[email protected]";
- let notification_ids = vec![
- "0193b1ea-a542-7589-893b-2b4a509c1e76".to_string(),
- "0193b1ea-a542-7589-893b-2b4a509c1e75".to_string(),
- ];
-
- // Before patching, verify that these notifications are not marked as done.
- for notif_id in &notification_ids {
- let rec = sqlx::query!(
- r#"
- SELECT done as "done" FROM user_notification
- WHERE user_id = $1 AND notification_id = $2
- "#,
- user_id,
- macro_uuid::string_to_uuid(notif_id)?
- )
- .fetch_one(&pool)
- .await?;
- assert!(
- !rec.done,
- "Notification {} is already marked as done",
- notif_id
- );
- }
-
- // Perform bulk patch: mark the notifications as done.
- bulk_patch_done(&pool, user_id, &notification_ids).await?;
-
- // Verify that the notifications are now marked as done.
- for notif_id in &notification_ids {
- let rec = sqlx::query!(
- r#"
- SELECT done as "done" FROM user_notification
- WHERE user_id = $1 AND notification_id = $2
- "#,
- user_id,
- macro_uuid::string_to_uuid(notif_id)?
- )
- .fetch_optional(&pool)
- .await?;
- assert!(rec.is_none(), "Notification {} was not deleted", notif_id);
- }
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("user_notifications")))]
- async fn test_bulk_patch_done_by_event(pool: Pool<Postgres>) -> anyhow::Result<()> {
- bulk_patch_done_by_event(&pool, "macro|[email protected]", "test").await?;
-
- Ok(())
- }
-}
+mod test;
diff --git a/rust/cloud-storage/notification_db_client/src/user_notification/patch/done/test.rs b/rust/cloud-storage/notification_db_client/src/user_notification/patch/done/test.rs
new file mode 100644
index 0000000000..62bd414555
--- /dev/null
+++ b/rust/cloud-storage/notification_db_client/src/user_notification/patch/done/test.rs
@@ -0,0 +1,117 @@
+use super::*;
+use sqlx::{Pool, Postgres};
+
+#[sqlx::test(fixtures(path = "../../../../fixtures", scripts("user_notifications")))]
+async fn test_bulk_patch_undone(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = "macro|[email protected]";
+ let notification_ids = vec![
+ macro_uuid::string_to_uuid("0193b1ea-a542-7589-893b-2b4a509c1e76")?,
+ macro_uuid::string_to_uuid("0193b1ea-a542-7589-893b-2b4a509c1e75")?,
+ ];
+
+ // Before patching mark the notifications as done.
+ for notif_id in &notification_ids {
+ patch_done(&pool, &notif_id.to_string(), user_id).await?;
+ }
+
+ bulk_patch_done(&pool, user_id, &notification_ids, false).await?;
+
+ // Verify that the notifications are now marked as undone.
+ for notif_id in &notification_ids {
+ let rec = sqlx::query!(
+ r#"
+ SELECT done as "done" FROM user_notification
+ WHERE user_id = $1 AND notification_id = $2
+ "#,
+ user_id,
+ notif_id
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert!(
+ !rec.done,
+ "Notification {} was not marked as undone",
+ notif_id
+ );
+ }
+
+ Ok(())
+}
+
+#[sqlx::test(fixtures(path = "../../../../fixtures", scripts("user_notifications")))]
+async fn test_patch_done(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let notification_id = "0193b1ea-a542-7589-893b-2b4a509c1e76";
+ let user_id = "macro|[email protected]";
+
+ patch_done(&pool, notification_id, user_id).await?;
+
+ let notification: bool = sqlx::query!(
+ r#"
+ SELECT done as "done" FROM user_notification WHERE notification_id = $1 AND user_id = $2
+ "#,
+ macro_uuid::string_to_uuid(notification_id)?,
+ user_id,
+ )
+ .map(|n| n.done)
+ .fetch_one(&pool)
+ .await?;
+
+ assert!(notification);
+
+ Ok(())
+}
+
+#[sqlx::test(fixtures(path = "../../../../fixtures", scripts("user_notifications")))]
+async fn test_bulk_patch_done(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = "macro|[email protected]";
+ let notification_ids = vec![
+ macro_uuid::string_to_uuid("0193b1ea-a542-7589-893b-2b4a509c1e76")?,
+ macro_uuid::string_to_uuid("0193b1ea-a542-7589-893b-2b4a509c1e75")?,
+ ];
+
+ // Before patching, verify that these notifications are not marked as done.
+ for notif_id in &notification_ids {
+ let rec = sqlx::query!(
+ r#"
+ SELECT done as "done" FROM user_notification
+ WHERE user_id = $1 AND notification_id = $2
+ "#,
+ user_id,
+ notif_id
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert!(
+ !rec.done,
+ "Notification {} is already marked as done",
+ notif_id
+ );
+ }
+
+ // Perform bulk patch: mark the notifications as done.
+ bulk_patch_done(&pool, user_id, &notification_ids, true).await?;
+
+ // Verify that the notifications are now marked as done.
+ for notif_id in &notification_ids {
+ let rec = sqlx::query!(
+ r#"
+ SELECT done as "done" FROM user_notification
+ WHERE user_id = $1 AND notification_id = $2
+ "#,
+ user_id,
+ notif_id
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert!(rec.done, "Notification {} was not marked as done", notif_id);
+ }
+
+ Ok(())
+}
+
+#[sqlx::test(fixtures(path = "../../../../fixtures", scripts("user_notifications")))]
+async fn test_bulk_patch_done_by_event(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ bulk_patch_done_by_event(&pool, "macro|[email protected]", "test").await?;
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/notification_db_client/src/user_notification/patch/seen.rs b/rust/cloud-storage/notification_db_client/src/user_notification/patch/seen.rs
index 4c5539bb48..473d1305cc 100644
--- a/rust/cloud-storage/notification_db_client/src/user_notification/patch/seen.rs
+++ b/rust/cloud-storage/notification_db_client/src/user_notification/patch/seen.rs
@@ -27,12 +27,8 @@ pub async fn patch_seen(
pub async fn bulk_patch_seen(
db: &sqlx::Pool<sqlx::Postgres>,
user_id: &str,
- notification_ids: &Vec<String>,
+ notification_ids: &Vec<uuid::Uuid>,
) -> anyhow::Result<()> {
- let notification_uuids = notification_ids
- .iter()
- .map(|id| macro_uuid::string_to_uuid(id))
- .collect::<Result<Vec<Uuid>, _>>()?;
sqlx::query!(
r#"
UPDATE user_notification un SET seen_at = NOW()
@@ -40,7 +36,7 @@ pub async fn bulk_patch_seen(
AND un.notification_id = ANY($2)
"#,
user_id,
- &notification_uuids,
+ notification_ids,
)
.execute(db)
.await?;
@@ -77,88 +73,4 @@ pub async fn bulk_patch_seen_by_event(
}
#[cfg(test)]
-mod tests {
- use super::*;
- use sqlx::{Pool, Postgres};
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("user_notifications")))]
-
- async fn test_patch_seen(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let notification_id = "0193b1ea-a542-7589-893b-2b4a509c1e76";
- let user_id = "macro|[email protected]";
-
- patch_seen(&pool, notification_id, user_id).await?;
-
- let notification = sqlx::query!(
- r#"
- SELECT seen_at as "seen_at?" FROM user_notification WHERE notification_id = $1 AND user_id = $2
- "#,
- macro_uuid::string_to_uuid(notification_id)?,
- user_id,
- )
- .fetch_one(&pool)
- .await?;
-
- assert!(notification.seen_at.is_some());
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("user_notifications")))]
- async fn test_bulk_patch_seen(pool: Pool<Postgres>) -> anyhow::Result<()> {
- let user_id = "macro|[email protected]";
- let notification_ids = vec![
- "0193b1ea-a542-7589-893b-2b4a509c1e76".to_string(),
- "0193b1ea-a542-7589-893b-2b4a509c1e75".to_string(),
- ];
-
- // Before patching, verify that these notifications are not marked as seen.
- for notif_id in &notification_ids {
- let rec = sqlx::query!(
- r#"
- SELECT seen_at as "seen_at?" FROM user_notification
- WHERE user_id = $1 AND notification_id = $2
- "#,
- user_id,
- macro_uuid::string_to_uuid(notif_id)?
- )
- .fetch_one(&pool)
- .await?;
- assert!(
- rec.seen_at.is_none(),
- "Notification {} is already marked as seen",
- notif_id
- );
- }
-
- // Perform bulk patch: mark the notifications as seen.
- bulk_patch_seen(&pool, user_id, &notification_ids).await?;
-
- // Verify that the notifications are now marked as seen.
- for notif_id in &notification_ids {
- let rec = sqlx::query!(
- r#"
- SELECT seen_at as "seen_at?" FROM user_notification
- WHERE user_id = $1 AND notification_id = $2
- "#,
- user_id,
- macro_uuid::string_to_uuid(notif_id)?
- )
- .fetch_one(&pool)
- .await?;
- assert!(
- rec.seen_at.is_some(),
- "Notification {} was not marked as seen",
- notif_id
- );
- }
-
- Ok(())
- }
-
- #[sqlx::test(fixtures(path = "../../../fixtures", scripts("user_notifications")))]
- async fn test_bulk_patch_seen_by_event(pool: Pool<Postgres>) -> anyhow::Result<()> {
- bulk_patch_seen_by_event(&pool, "macro|[email protected]", "test").await?;
-
- Ok(())
- }
-}
+mod test;
diff --git a/rust/cloud-storage/notification_db_client/src/user_notification/patch/seen/test.rs b/rust/cloud-storage/notification_db_client/src/user_notification/patch/seen/test.rs
new file mode 100644
index 0000000000..96e5bed4d6
--- /dev/null
+++ b/rust/cloud-storage/notification_db_client/src/user_notification/patch/seen/test.rs
@@ -0,0 +1,83 @@
+use super::*;
+use sqlx::{Pool, Postgres};
+#[sqlx::test(fixtures(path = "../../../../fixtures", scripts("user_notifications")))]
+
+async fn test_patch_seen(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let notification_id = "0193b1ea-a542-7589-893b-2b4a509c1e76";
+ let user_id = "macro|[email protected]";
+
+ patch_seen(&pool, notification_id, user_id).await?;
+
+ let notification = sqlx::query!(
+ r#"
+ SELECT seen_at as "seen_at?" FROM user_notification WHERE notification_id = $1 AND user_id = $2
+ "#,
+ macro_uuid::string_to_uuid(notification_id)?,
+ user_id,
+ )
+ .fetch_one(&pool)
+ .await?;
+
+ assert!(notification.seen_at.is_some());
+
+ Ok(())
+}
+
+#[sqlx::test(fixtures(path = "../../../../fixtures", scripts("user_notifications")))]
+async fn test_bulk_patch_seen(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ let user_id = "macro|[email protected]";
+ let notification_ids = vec![
+ macro_uuid::string_to_uuid("0193b1ea-a542-7589-893b-2b4a509c1e76")?,
+ macro_uuid::string_to_uuid("0193b1ea-a542-7589-893b-2b4a509c1e75")?,
+ ];
+
+ // Before patching, verify that these notifications are not marked as seen.
+ for notif_id in &notification_ids {
+ let rec = sqlx::query!(
+ r#"
+ SELECT seen_at as "seen_at?" FROM user_notification
+ WHERE user_id = $1 AND notification_id = $2
+ "#,
+ user_id,
+ notif_id,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert!(
+ rec.seen_at.is_none(),
+ "Notification {} is already marked as seen",
+ notif_id
+ );
+ }
+
+ // Perform bulk patch: mark the notifications as seen.
+ bulk_patch_seen(&pool, user_id, &notification_ids).await?;
+
+ // Verify that the notifications are now marked as seen.
+ for notif_id in &notification_ids {
+ let rec = sqlx::query!(
+ r#"
+ SELECT seen_at as "seen_at?" FROM user_notification
+ WHERE user_id = $1 AND notification_id = $2
+ "#,
+ user_id,
+ notif_id,
+ )
+ .fetch_one(&pool)
+ .await?;
+ assert!(
+ rec.seen_at.is_some(),
+ "Notification {} was not marked as seen",
+ notif_id
+ );
+ }
+
+ Ok(())
+}
+
+#[sqlx::test(fixtures(path = "../../../../fixtures", scripts("user_notifications")))]
+async fn test_bulk_patch_seen_by_event(pool: Pool<Postgres>) -> anyhow::Result<()> {
+ bulk_patch_seen_by_event(&pool, "macro|[email protected]", "test").await?;
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/notification_service/Cargo.toml b/rust/cloud-storage/notification_service/Cargo.toml
index b8cc6876f7..9d0834d251 100644
--- a/rust/cloud-storage/notification_service/Cargo.toml
+++ b/rust/cloud-storage/notification_service/Cargo.toml
@@ -78,6 +78,7 @@ url = { workspace = true }
utoipa = { workspace = true }
utoipa-swagger-ui = { workspace = true }
authentication_service_client = { path = "../authentication_service_client" }
+uuid = { workspace = true }
[dev-dependencies]
macro_auth = { path = "../macro_auth", features = ["testing"] }
diff --git a/rust/cloud-storage/notification_service/src/api/swagger.rs b/rust/cloud-storage/notification_service/src/api/swagger.rs
index d8b3e674de..e538539414 100644
--- a/rust/cloud-storage/notification_service/src/api/swagger.rs
+++ b/rust/cloud-storage/notification_service/src/api/swagger.rs
@@ -48,6 +48,7 @@ use crate::{
user_notification::bulk_mark_user_notification_done::handler,
user_notification::get_user_notifications_by_event_item_id::handler,
user_notification::bulk_get_user_notifications_by_event_item_id::handler,
+ user_notification::bulk_mark_user_notification_undone::handler,
/// /unsubscribe
unsubscribe::get_unsubscribes::handler,
diff --git a/rust/cloud-storage/notification_service/src/api/user_notification/bulk_mark_user_notification_done.rs b/rust/cloud-storage/notification_service/src/api/user_notification/bulk_mark_user_notification_done.rs
index dee3bb32a5..5e6f80ed77 100644
--- a/rust/cloud-storage/notification_service/src/api/user_notification/bulk_mark_user_notification_done.rs
+++ b/rust/cloud-storage/notification_service/src/api/user_notification/bulk_mark_user_notification_done.rs
@@ -33,6 +33,7 @@ pub async fn handler(
&ctx.db,
&user_context.user_id,
&notification_ids,
+ true,
)
.await
.map_err(|e| {
diff --git a/rust/cloud-storage/notification_service/src/api/user_notification/bulk_mark_user_notification_undone.rs b/rust/cloud-storage/notification_service/src/api/user_notification/bulk_mark_user_notification_undone.rs
new file mode 100644
index 0000000000..828e8bf89c
--- /dev/null
+++ b/rust/cloud-storage/notification_service/src/api/user_notification/bulk_mark_user_notification_undone.rs
@@ -0,0 +1,59 @@
+use axum::{
+ Extension, Json,
+ extract::State,
+ http::StatusCode,
+ response::{IntoResponse, Response},
+};
+use model::response::{EmptyResponse, ErrorResponse};
+
+use crate::{api::context::ApiContext, model::user_notification::NotificationBulkRequest};
+use model::user::UserContext;
+
+#[derive(Debug, thiserror::Error)]
+pub enum BulkMarkUserNotificationUndoneError {
+ #[error("failed to patch user notifications undone")]
+ InternalServerError(#[from] anyhow::Error),
+}
+
+impl IntoResponse for BulkMarkUserNotificationUndoneError {
+ fn into_response(self) -> Response {
+ match self {
+ BulkMarkUserNotificationUndoneError::InternalServerError(e) => (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ Json(ErrorResponse {
+ message: &e.to_string(),
+ }),
+ )
+ .into_response(),
+ }
+ }
+}
+
+/// Marks the user's notifications as undone.
+#[utoipa::path(
+ patch,
+ operation_id = "bulk_mark_user_notification_undone",
+ path = "/user_notifications/bulk/undone",
+ responses(
+ (status = 200, body=EmptyResponse),
+ )
+ )]
+#[tracing::instrument(skip(ctx, user_context), fields(user_id=?user_context.user_id), err)]
+pub async fn handler(
+ State(ctx): State<ApiContext>,
+ user_context: Extension<UserContext>,
+ Json(req): Json<NotificationBulkRequest>,
+) -> Result<Json<EmptyResponse>, BulkMarkUserNotificationUndoneError> {
+ tracing::info!("bulk_mark_user_notification_undone");
+
+ let notification_ids = req.notification_ids;
+ notification_db_client::user_notification::patch::done::bulk_patch_done(
+ &ctx.db,
+ &user_context.user_id,
+ &notification_ids,
+ false,
+ )
+ .await?;
+
+ Ok(Json(EmptyResponse::default()))
+}
diff --git a/rust/cloud-storage/notification_service/src/api/user_notification/mod.rs b/rust/cloud-storage/notification_service/src/api/user_notification/mod.rs
index b6eb15b1e0..e477180d50 100644
--- a/rust/cloud-storage/notification_service/src/api/user_notification/mod.rs
+++ b/rust/cloud-storage/notification_service/src/api/user_notification/mod.rs
@@ -10,6 +10,7 @@ pub(in crate::api) mod bulk_mark_user_notification_done;
pub(in crate::api) mod bulk_mark_user_notification_done_by_event;
pub(in crate::api) mod bulk_mark_user_notification_seen;
pub(in crate::api) mod bulk_mark_user_notification_seen_by_event;
+pub(in crate::api) mod bulk_mark_user_notification_undone;
pub(in crate::api) mod delete_user_notification;
pub(in crate::api) mod get_user_notification;
pub(in crate::api) mod get_user_notifications_by_event_item_id;
@@ -38,6 +39,10 @@ pub fn router() -> Router<ApiContext> {
"/bulk/done",
patch(bulk_mark_user_notification_done::handler),
)
+ .route(
+ "/bulk/undone",
+ patch(bulk_mark_user_notification_undone::handler),
+ )
.route(
"/item/:event_item_id/seen",
patch(bulk_mark_user_notification_seen_by_event::handler),
diff --git a/rust/cloud-storage/notification_service/src/model/user_notification.rs b/rust/cloud-storage/notification_service/src/model/user_notification.rs
index e70b45a643..2a8dca85b8 100644
--- a/rust/cloud-storage/notification_service/src/model/user_notification.rs
+++ b/rust/cloud-storage/notification_service/src/model/user_notification.rs
@@ -5,5 +5,5 @@ use utoipa::ToSchema;
#[serde(rename_all = "camelCase")]
pub struct NotificationBulkRequest {
/// The ids of the notifications to handle
- pub notification_ids: Vec<String>,
+ pub notification_ids: Vec<uuid::Uuid>,
}
diff --git a/rust/cloud-storage/notification_service/src/notification/send/push/remove.rs b/rust/cloud-storage/notification_service/src/notification/send/push/remove.rs
index d914e024ba..73e909f8f9 100644
--- a/rust/cloud-storage/notification_service/src/notification/send/push/remove.rs
+++ b/rust/cloud-storage/notification_service/src/notification/send/push/remove.rs
@@ -14,7 +14,7 @@ use crate::{api::context::ApiContext, config::APPLE_BUNDLE_ID};
#[tracing::instrument(skip(ctx))]
pub fn clear_push_notifications(
ctx: ApiContext,
- notification_ids: &[String],
+ notification_ids: &[uuid::Uuid],
user_id: &str,
) -> anyhow::Result<()> {
tracing::trace!("clearing potential push notifications");
@@ -44,7 +44,6 @@ pub fn clear_push_notifications(
let _ = futures::stream::iter(notification_ids.iter())
.then(|notification_id| {
- let notification_id = notification_id.clone();
let sns_client = sns_client.clone();
let db = db.clone();
let user_id = user_id.clone();
@@ -55,12 +54,12 @@ pub fn clear_push_notifications(
&db,
&sns_client,
&device_endpoints,
- Some(&notification_id),
+ Some(&notification_id.to_string()),
None,
)
.await
{
- tracing::error!(error=?e, notification_id=notification_id, user_id=user_id, "failed to remove push notification");
+ tracing::error!(error=?e, notification_id=notification_id.to_string(), user_id=user_id, "failed to remove push notification");
}
Ok(())