From 5b55a5e6aaed5013991332d1dd663c1d94a20035 Mon Sep 17 00:00:00 2001 From: lantry-glitch <allan.kwek.18@gmail.com> Date: Fri, 28 Mar 2025 13:26:00 +0700 Subject: [PATCH] Implement unsubscribe function in Notification service. --- src/service/notification.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/service/notification.rs b/src/service/notification.rs index 1ec87b4..0e747e3 100644 --- a/src/service/notification.rs +++ b/src/service/notification.rs @@ -15,4 +15,19 @@ 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()); + } + } -- GitLab