From e64b30e2467d7348994ec8573695210738acfa48 Mon Sep 17 00:00:00 2001 From: lantry-glitch <allan.kwek.18@gmail.com> Date: Fri, 28 Mar 2025 15:56:15 +0700 Subject: [PATCH] Implement the receive function in Notification controller. --- src/controller/mod.rs | 4 +++- src/controller/notification.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/controller/mod.rs b/src/controller/mod.rs index 2e4d6d9..71470e2 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -4,7 +4,9 @@ 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 37c67cc..9418201 100644 --- a/src/controller/notification.rs +++ b/src/controller/notification.rs @@ -22,3 +22,11 @@ pub fn unsubscribe(product_type: &str) -> Result<Json<SubscriberRequest>> { }; } +#[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