From a6047dc24ce1eb1bdf5a8e353cb804cad8f7eb84 Mon Sep 17 00:00:00 2001 From: Scallss <pascalhafidz2005@gmail.com> Date: Fri, 28 Mar 2025 16:21:17 +0700 Subject: [PATCH] Implement update method in Subscriber model to send notification HTTP requests. --- src/model/subscriber.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/model/subscriber.rs b/src/model/subscriber.rs index dfdc8c5..b2e52f7 100644 --- a/src/model/subscriber.rs +++ b/src/model/subscriber.rs @@ -10,4 +10,20 @@ use crate::model::notification::Notification; pub struct Subscriber { pub url: String, pub name:String, -} \ No newline at end of file +} + +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: {}", + payload.status, payload.product_type, payload.product_title, self.url + ); + } +} -- GitLab