From 110f1199a4be962e37efdfe58f147e2f9f194ebf Mon Sep 17 00:00:00 2001 From: asShidqi <fayyed76@gmail.com> Date: Fri, 28 Mar 2025 20:47:01 +0700 Subject: [PATCH] Edit Product service methods to call notify after create/delete. --- src/service/notification.rs | 2 +- src/service/product.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/service/notification.rs b/src/service/notification.rs index fd2d534..2ffa158 100644 --- a/src/service/notification.rs +++ b/src/service/notification.rs @@ -27,7 +27,7 @@ impl NotificationService { return Ok(subscriber_result.unwrap()); } - pub fn notify(self, product_type: &str, status: &str, product: Product) { + 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), diff --git a/src/service/product.rs b/src/service/product.rs index f161b4d..67825ee 100644 --- a/src/service/product.rs +++ b/src/service/product.rs @@ -2,8 +2,10 @@ use rocket::http::Status; use rocket::serde::json::Json; use bambangshop::{Result, compose_error_response}; +use crate::model::notification::Notification; use crate::model::product::Product; use crate::repository::product::ProductRepository; +use crate::service::notification::NotificationService; // Import NotificationService pub struct ProductService; @@ -12,6 +14,7 @@ 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); } @@ -40,6 +43,7 @@ impl ProductService { } let product: Product = product_opt.unwrap(); + NotificationService.notify(&product.product_type, "DELETED", product.clone()); return Ok(Json::from(product)); } @@ -54,7 +58,6 @@ impl ProductService { } let product: Product = product_opt.unwrap(); - NotificationService.notify(&product.product_type, "PROMOTION", product.clone()); return Ok(product); -- GitLab