diff --git a/src/service/notification.rs b/src/service/notification.rs index 4f99fee35e45bc345b266053ef09fb821c09a262..8af79fd5ad0e62b601e8d9b016a9fcd07f594c8d 100644 --- a/src/service/notification.rs +++ b/src/service/notification.rs @@ -14,7 +14,23 @@ impl NotificationService { let product_type_str: &str = product_type_upper.as_str(); 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