diff --git a/src/controller/mod.rs b/src/controller/mod.rs index 80195c40910ace8157102b9c97495f2e5d822632..b851bd2cb5caa8a599ec722c9c39fb3bf2357202 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 ce8ae619148902dd0736c2cdb31eed5e37c05e65..5211f06ff88bd9c043a7d56afe5ff7414525d257 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 15eddc3eb08285b99a55c43c81fe5311a6968fe4..2c286c759dfce1a9196cca03e8b056576f3f2594 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); }