From 2fb8f9b62e7bf2c4010f7cbb2c69e6616f73f137 Mon Sep 17 00:00:00 2001
From: DawnFall19 <ignasius.michael09@gmail.com>
Date: Fri, 28 Mar 2025 18:30:58 +0700
Subject: [PATCH] Implement the receive function in Notification controller.

---
 src/controller/mod.rs          | 3 ++-
 src/controller/notification.rs | 8 ++++++++
 src/service/notification.rs    | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/controller/mod.rs b/src/controller/mod.rs
index 80195c4..b851bd2 100644
--- a/src/controller/mod.rs
+++ b/src/controller/mod.rs
@@ -5,6 +5,7 @@ use rocket::fairing::AdHoc;
 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 ce8ae61..5211f06 100644
--- a/src/controller/notification.rs
+++ b/src/controller/notification.rs
@@ -22,4 +22,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
diff --git a/src/service/notification.rs b/src/service/notification.rs
index 15eddc3..2c286c7 100644
--- a/src/service/notification.rs
+++ b/src/service/notification.rs
@@ -91,7 +91,7 @@ impl NotificationService {
             .join().unwrap();
     }
 
-    pub fn receiver_notification(payload: Notification) -> Result<Notification> {
+    pub fn receive_notification(payload: Notification) -> Result<Notification> {
         let subscriber_result: Notification = NotificationRepository::add(payload);
         return Ok(subscriber_result);
     }
-- 
GitLab