From 543bab7ff6c31fd9d78a2ec952159e0f2ec0f791 Mon Sep 17 00:00:00 2001 From: TheoKevH <theodorekevinh@gmail.com> Date: Fri, 28 Mar 2025 19:10:18 +0700 Subject: [PATCH] Implement unsubscribe function in Notification service --- src/service/notification.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/service/notification.rs b/src/service/notification.rs index fa9e008..3e2c671 100644 --- a/src/service/notification.rs +++ b/src/service/notification.rs @@ -16,4 +16,17 @@ impl NotificationService { let subscriber_result : Subscriber = SubscriberRepository::add(product_type_str, subscriber); return Ok(subscriber_result); } + + pub fn unsubscribe(product_type: &str, url: &str) -> Result<Subscriber> { + let product_type_upper: String = product_type.to_uppercase(); + let product_type_str: &str = &product_type_upper.as_str(); + let result: Option<Subscriber> = SubscriberRepository::delete(product_type_str, url); + if result.is_none() { + return Err(compose_error_response( + Status::NotFound, + String::from("Subscriber not found.") + )); + } + return Ok(result.unwrap()); + } } \ No newline at end of file -- GitLab