From bbdb5479e2f321fa43ba96997df10b11396d830a Mon Sep 17 00:00:00 2001
From: Andrew4Coding <andrewdevitoaryo@gmail.com>
Date: Fri, 28 Mar 2025 01:19:07 +0800
Subject: [PATCH] Implement unsubscribe function in Notification service

---
 src/service/notification.rs | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/service/notification.rs b/src/service/notification.rs
index 23dc169..04ee358 100644
--- a/src/service/notification.rs
+++ b/src/service/notification.rs
@@ -1,4 +1,5 @@
-use bambangshop::Result;
+use bambangshop::{compose_error_response, Result};
+use rocket::http::Status;
 
 use crate::{model::subscriber::Subscriber, repository::subscriber::SubscriberRepository};
 
@@ -12,4 +13,16 @@ impl NotificationService {
 
         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, String::from("Subscriber not found")));
+        }
+
+        return Ok(result.unwrap());
+    }
 }
\ No newline at end of file
-- 
GitLab