Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 110f1199 authored by asShidqi's avatar asShidqi
Browse files

Edit Product service methods to call notify after create/delete.

parent 8433255e
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ impl NotificationService { ...@@ -27,7 +27,7 @@ impl NotificationService {
return Ok(subscriber_result.unwrap()); 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 { let mut payload: Notification = Notification {
product_title: product.clone().title, product_title: product.clone().title,
product_type: String::from(product_type), product_type: String::from(product_type),
......
...@@ -2,8 +2,10 @@ use rocket::http::Status; ...@@ -2,8 +2,10 @@ use rocket::http::Status;
use rocket::serde::json::Json; use rocket::serde::json::Json;
use bambangshop::{Result, compose_error_response}; use bambangshop::{Result, compose_error_response};
use crate::model::notification::Notification;
use crate::model::product::Product; use crate::model::product::Product;
use crate::repository::product::ProductRepository; use crate::repository::product::ProductRepository;
use crate::service::notification::NotificationService; // Import NotificationService
pub struct ProductService; pub struct ProductService;
...@@ -12,6 +14,7 @@ impl ProductService { ...@@ -12,6 +14,7 @@ impl ProductService {
product.product_type = product.product_type.to_uppercase(); product.product_type = product.product_type.to_uppercase();
let product_result: Product = ProductRepository::add(product); let product_result: Product = ProductRepository::add(product);
NotificationService.notify(&product_result.product_type, "CREATED", product_result.clone());
return Ok(product_result); return Ok(product_result);
} }
...@@ -40,6 +43,7 @@ impl ProductService { ...@@ -40,6 +43,7 @@ impl ProductService {
} }
let product: Product = product_opt.unwrap(); let product: Product = product_opt.unwrap();
NotificationService.notify(&product.product_type, "DELETED", product.clone());
return Ok(Json::from(product)); return Ok(Json::from(product));
} }
...@@ -54,7 +58,6 @@ impl ProductService { ...@@ -54,7 +58,6 @@ impl ProductService {
} }
let product: Product = product_opt.unwrap(); let product: Product = product_opt.unwrap();
NotificationService.notify(&product.product_type, "PROMOTION", product.clone()); NotificationService.notify(&product.product_type, "PROMOTION", product.clone());
return Ok(product); return Ok(product);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment