From 3b0b078e02429f92e8ce3f87e70c37c344895bcb Mon Sep 17 00:00:00 2001
From: Christian Raphael Heryanto <christian.raphael@ui.ac.id>
Date: Fri, 28 Mar 2025 16:27:06 +0800
Subject: [PATCH] Implement the receive function in Notification controller.

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

diff --git a/src/controller/mod.rs b/src/controller/mod.rs
index f76c4f3..b6d9501 100644
--- a/src/controller/mod.rs
+++ b/src/controller/mod.rs
@@ -5,7 +5,11 @@ pub fn route_stage() -> AdHoc {
     return AdHoc::on_ignite("Initializing controller routes...", |rocket| async {
         rocket.mount(
             "/",
-            routes![notification::subscribe, notification::unsubscribe],
+            routes![
+                notification::subscribe,
+                notification::unsubscribe,
+                notification::receive
+            ],
         )
     });
 }
diff --git a/src/controller/notification.rs b/src/controller/notification.rs
index 0677a67..18af254 100644
--- a/src/controller/notification.rs
+++ b/src/controller/notification.rs
@@ -20,3 +20,11 @@ pub fn unsubscribe(product_type: &str) -> Result<Json<SubscriberRequest>> {
         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),
+    };
+}
-- 
GitLab