From bd96542d6ecc2f5c021a6bb2d62a37656899b988 Mon Sep 17 00:00:00 2001
From: vissutagunawan <vglim3653@gmail.com>
Date: Thu, 27 Mar 2025 09:45:34 +0700
Subject: [PATCH] Edit Product service methods to call notify after
 create/delete.

---
 src/controller/notification.rs | 2 --
 src/service/product.rs         | 8 ++++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/controller/notification.rs b/src/controller/notification.rs
index 9cc0c6a..f331102 100644
--- a/src/controller/notification.rs
+++ b/src/controller/notification.rs
@@ -5,8 +5,6 @@ use crate::model::subscriber::Subscriber;
 use crate::service::notification::NotificationService;
 use bambangshop::Result;
 
-use super::product;
-
 #[post("/subscribe/<product_type>", data = "<subscriber>")]
  pub fn subscribe(
      product_type: &str,
diff --git a/src/service/product.rs b/src/service/product.rs
index 8369537..88a228e 100644
--- a/src/service/product.rs
+++ b/src/service/product.rs
@@ -14,6 +14,12 @@ impl ProductService {
         product.product_type = product.product_type.to_uppercase();
         let product_result: Product = ProductRepository::add(product);
 
+        NotificationService.notify(
+            &product_result.product_type,
+            "CREATED",
+            product_result.clone(),
+        );
+
         return Ok(product_result);
     }
 
@@ -42,6 +48,8 @@ impl ProductService {
         }
         let product: Product = product_opt.unwrap();
 
+        NotificationService.notify(&product.product_type, "DELETED", product.clone());
+
         return Ok(Json::from(product));
     }
 
-- 
GitLab