Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 1f9d3056 authored by asShidqi's avatar asShidqi
Browse files

Implementation notify function in Notification service to notify each Subscriber.

parent d08363f0
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,7 @@ pub struct Subscriber {
pub name: String,
}
impl subscriber {
impl Subscriber {
#[tokio::main]
pub async fn update(&self, payload: Notification){
REQWEST_CLIENT
......
......@@ -26,4 +26,22 @@ impl NotificationService {
}
return Ok(subscriber_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 payload_clone = payload.clone();
thread::spawn(move || subscriber.update(payload_clone));
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment