From d09732bcb73c2ac9124cca2b1cd1840fc4343cd2 Mon Sep 17 00:00:00 2001
From: TheoKevH <theodorekevinh@gmail.com>
Date: Fri, 28 Mar 2025 19:17:14 +0700
Subject: [PATCH] Implement notify function in Notification service to notify
 each Subscriber

---
 src/service/notification.rs | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/service/notification.rs b/src/service/notification.rs
index 3e2c671..e142dce 100644
--- a/src/service/notification.rs
+++ b/src/service/notification.rs
@@ -29,4 +29,22 @@ impl NotificationService {
         }
         return Ok(result.unwrap());
     }
+
+    pub fn notify(&self, product_type: &str, status: &str, product: Product) {
+        let mut payload: Notification = Notification {
+            product_title : product.clone().title,
+            product_type: String::from(product_type),
+            product_url: product.clone().get_url(),
+            subscriber_name: String::from(""),
+            status: String::from(status)
+        };
+
+        let subscribers: Vec<Subscriber> = SubscriberRepository::list_all(product_type);
+        for subscriber in subscribers {
+            payload.subscriber_name = subscriber.clone().name;
+            let subscriber_clone = subscriber.clone();
+            let payload_clone = payload.clone();
+            thread::spawn(move|| subscriber_clone.update(payload_clone));
+        }
+    }
 }
\ No newline at end of file
-- 
GitLab