From 02a4431a133624064d4f75387f46b648d7778644 Mon Sep 17 00:00:00 2001 From: Ferdinand57 <ferdinandbs77@gmail.com> Date: Fri, 28 Mar 2025 20:00:13 +0700 Subject: [PATCH] Implement update method in Subscriber model to send notification HTTP requests. --- src/model/subscriber.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/model/subscriber.rs b/src/model/subscriber.rs index 48b36e8..1d1e8f3 100644 --- a/src/model/subscriber.rs +++ b/src/model/subscriber.rs @@ -10,4 +10,18 @@ use crate::model::notification::Notification; pub struct Subscriber { pub url: String, pub name: String, +} + +impl Subscriber { + #[tokio::main] + pub async fn update(&self, payload: Notification) { + REQUEST_CLIENT + .post(&self.url) + .header("Content-Type", "JSON") // Note: Should probably be "application/json" + .body(to_string(&payload).unwrap()) + .send().await.ok(); // Note: It might be better to handle potential errors here + + log::warn_!("Sent {} notification of: [{}] {}, to: {}", + payload.status, payload.product_type, payload.product_title, self.url); + } } \ No newline at end of file -- GitLab