From ad92bfdd7465fa7a244020443a301397bad13995 Mon Sep 17 00:00:00 2001
From: Scallss <pascalhafidz2005@gmail.com>
Date: Fri, 28 Mar 2025 17:48:58 +0700
Subject: [PATCH] Implement the receive function in Notification controller.

---
 src/controller/mod.rs          | 2 +-
 src/controller/notification.rs | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/controller/mod.rs b/src/controller/mod.rs
index 15f8ce2..46b0824 100644
--- a/src/controller/mod.rs
+++ b/src/controller/mod.rs
@@ -7,6 +7,6 @@ pub mod notification;
 pub fn route_stage() -> AdHoc {
     return AdHoc::on_ignite("Initializing controller routes...", |rocket| async {
         rocket
-            .mount("/", routes![notification::subscribe, notification::unsubscribe])
+            .mount("/", routes![notification::subscribe, notification::unsubscribe, notification::receive])
     });
 }
diff --git a/src/controller/notification.rs b/src/controller/notification.rs
index fe291ee..1b7e27b 100644
--- a/src/controller/notification.rs
+++ b/src/controller/notification.rs
@@ -19,4 +19,12 @@ pub fn unsubscribe(product_type: &str) -> Result<Json<SubscriberRequest>> {
         Ok(f) => Ok(Json::from(f)),
         Err(e) => Err(e)
     };
+}
+
+#[post("/receive", data = "<notification>")]
+pub fn receive(notification: Json<Notification>) -> Result<Json<Notification>> {
+    return match NotificationService::receive_notification(notification.into_inner()) {
+        Ok(f) => Ok(Json::from(f)),
+        Err(e) => Err(e)
+    };
 }
\ No newline at end of file
-- 
GitLab