From 1c5e6137cd200cb310f761046af42cb2e1481658 Mon Sep 17 00:00:00 2001
From: Christian Raphael Heryanto <christian.raphael@ui.ac.id>
Date: Fri, 28 Mar 2025 12:54:50 +0800
Subject: [PATCH] Implement update method in Subscriber model to send
 notification HTTP requests.

---
 src/model/subscriber.rs | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/model/subscriber.rs b/src/model/subscriber.rs
index bad01dc..1abf023 100644
--- a/src/model/subscriber.rs
+++ b/src/model/subscriber.rs
@@ -11,3 +11,23 @@ pub struct Subscriber {
     pub url: String,
     pub name: String,
 }
+
+impl Subscriber {
+    #[tokio::main]
+    pub async fn update(&self, payload: Notification) {
+        REQWEST_CLIENT
+            .post(&self.url)
+            .header("Content-Type", "JSON")
+            .body(to_string(&payload).unwrap())
+            .send()
+            .await
+            .ok();
+        log::warn_!(
+            "Sent {} notification of : [{}] {}, to P{}",
+            payload.status,
+            payload.product_type,
+            payload.product_title,
+            self.url
+        )
+    }
+}
-- 
GitLab