From 705a51fa9e2329cd2f6e4fdf9f0448fc99382ba5 Mon Sep 17 00:00:00 2001 From: vissutagunawan <vglim3653@gmail.com> Date: Thu, 27 Mar 2025 09:21:44 +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 a48c4ce..b4e8939 100644 --- a/src/service/notification.rs +++ b/src/service/notification.rs @@ -15,4 +15,17 @@ impl NotificationService { let subscriber_result = SubscriberRepository::add(product_type_str, subscriber); return Ok(subscriber_result); } + + pub fn unsubscribe(product_type: &str, url: &str) -> Result<Subscriber> { + let product_type_upper = product_type.to_uppercase(); + let product_type_str = product_type_upper.as_str(); + let result = SubscriberRepository::delete(product_type_str, url); + if result.is_none() { + return Err(compose_error_response( + Status::NotFound, + "Subscriber not found".to_string(), + )); + } + return Ok(result.unwrap()); + } } \ No newline at end of file -- GitLab