From e2846fb6131b41205f2936c9369713cbf70c5249 Mon Sep 17 00:00:00 2001 From: Christian Raphael Heryanto <christian.raphael@ui.ac.id> Date: Fri, 28 Mar 2025 11:44:53 +0800 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 ab5a592..e436841 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()); + } } -- GitLab