From 6e063a73d3e427153d65e1e452ab2314130c6e55 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Fri, 9 Feb 2024 15:43:50 +0530 Subject: [PATCH] chore(notifications): more boilerplate for documents event --- core/notifications/locales/en.yml | 3 ++ core/notifications/proto/notifications.proto | 15 ++++++ core/notifications/src/app/mod.rs | 27 ++++++++++ core/notifications/src/grpc/server/mod.rs | 36 +++++++++++++ core/notifications/src/messages/mod.rs | 20 +++++++ core/notifications/src/notification_event.rs | 57 ++++++++++++++++++++ 6 files changed, 158 insertions(+) diff --git a/core/notifications/locales/en.yml b/core/notifications/locales/en.yml index bf558fd3c3..8040f1f186 100644 --- a/core/notifications/locales/en.yml +++ b/core/notifications/locales/en.yml @@ -14,3 +14,6 @@ circle_threshold_reached.inner.body: "You have welcomed %{threshold} people to B circle_threshold_reached.outer.title: "Outer Circle gains 💪" circle_threshold_reached.outer.body: "Your Outer Circle reached %{threshold} people. You are driving Bitcoin adoption!" + +documents_submitted.title: "Documents Received" +documents_submitted.body: "The documents for your verification are being processed." diff --git a/core/notifications/proto/notifications.proto b/core/notifications/proto/notifications.proto index 74c98aeac2..3ac4c58689 100644 --- a/core/notifications/proto/notifications.proto +++ b/core/notifications/proto/notifications.proto @@ -134,6 +134,9 @@ message NotificationEvent { CircleGrew circle_grew = 1; CircleThresholdReached circle_threshold_reached = 2; DocumentsSubmitted documents_submitted = 3; + DocumentsApproved documents_approved = 4; + DocumentsRejected documents_rejected = 5; + DocumentsReviewPending documents_review_pending = 6; } } @@ -164,3 +167,15 @@ message CircleThresholdReached { message DocumentsSubmitted { string user_id = 1; } + +message DocumentsApproved { + string user_id = 1; +} + +message DocumentsRejected { + string user_id = 1; +} + +message DocumentsReviewPending { + string user_id = 1; +} diff --git a/core/notifications/src/app/mod.rs b/core/notifications/src/app/mod.rs index 6ba7203bd9..0afd572f5a 100644 --- a/core/notifications/src/app/mod.rs +++ b/core/notifications/src/app/mod.rs @@ -172,4 +172,31 @@ impl NotificationsApp { self.executor.notify(event).await?; Ok(()) } + + #[instrument(name = "app.handle_documents_approved", skip(self), err)] + pub async fn handle_documents_approved( + &self, + event: DocumentsApproved, + ) -> Result<(), ApplicationError> { + self.executor.notify(event).await?; + Ok(()) + } + + #[instrument(name = "app.handle_documents_rejected", skip(self), err)] + pub async fn handle_documents_rejected( + &self, + event: DocumentsRejected, + ) -> Result<(), ApplicationError> { + self.executor.notify(event).await?; + Ok(()) + } + + #[instrument(name = "app.handle_documents_review_pending", skip(self), err)] + pub async fn handle_documents_review_pending( + &self, + event: DocumentsReviewPending, + ) -> Result<(), ApplicationError> { + self.executor.notify(event).await?; + Ok(()) + } } diff --git a/core/notifications/src/grpc/server/mod.rs b/core/notifications/src/grpc/server/mod.rs index 1f57ba9329..50762efb9d 100644 --- a/core/notifications/src/grpc/server/mod.rs +++ b/core/notifications/src/grpc/server/mod.rs @@ -297,6 +297,42 @@ impl NotificationsService for Notifications { }) .await? } + Some(proto::NotificationEvent { + data: + Some(proto::notification_event::Data::DocumentsApproved(proto::DocumentsApproved { + user_id, + })), + }) => { + self.app + .handle_documents_approved(notification_event::DocumentsApproved { + user_id: GaloyUserId::from(user_id), + }) + .await? + } + Some(proto::NotificationEvent { + data: + Some(proto::notification_event::Data::DocumentsRejected(proto::DocumentsRejected { + user_id, + })), + }) => { + self.app + .handle_documents_rejected(notification_event::DocumentsRejected { + user_id: GaloyUserId::from(user_id), + }) + .await? + } + Some(proto::NotificationEvent { + data: + Some(proto::notification_event::Data::DocumentsReviewPending( + proto::DocumentsReviewPending { user_id }, + )), + }) => { + self.app + .handle_documents_review_pending(notification_event::DocumentsReviewPending { + user_id: GaloyUserId::from(user_id), + }) + .await? + } _ => return Err(Status::invalid_argument("event is required")), } diff --git a/core/notifications/src/messages/mod.rs b/core/notifications/src/messages/mod.rs index fd29f065d9..19e977a5cc 100644 --- a/core/notifications/src/messages/mod.rs +++ b/core/notifications/src/messages/mod.rs @@ -61,6 +61,26 @@ impl Messages { let body = t!("documents_submitted.body", locale = locale).to_string(); LocalizedMessage { title, body } } + + pub fn documents_approved(locale: &str, _event: &DocumentsApproved) -> LocalizedMessage { + let title = t!("documents_approved.title", locale = locale).to_string(); + let body = t!("documents_approved.body", locale = locale).to_string(); + LocalizedMessage { title, body } + } + pub fn documents_rejected(locale: &str, _event: &DocumentsRejected) -> LocalizedMessage { + let title = t!("documents_rejected.title", locale = locale).to_string(); + let body = t!("documents_rejected.body", locale = locale).to_string(); + LocalizedMessage { title, body } + } + + pub fn documents_review_pending( + locale: &str, + _event: &DocumentsReviewPending, + ) -> LocalizedMessage { + let title = t!("documents_review_pending.title", locale = locale).to_string(); + let body = t!("documents_review_pending.body", locale = locale).to_string(); + LocalizedMessage { title, body } + } } #[cfg(test)] diff --git a/core/notifications/src/notification_event.rs b/core/notifications/src/notification_event.rs index a454be1659..fa859ea4a7 100644 --- a/core/notifications/src/notification_event.rs +++ b/core/notifications/src/notification_event.rs @@ -73,3 +73,60 @@ impl NotificationEvent for DocumentsSubmitted { Messages::documents_submitted(locale.as_ref(), self) } } + +#[derive(Debug)] +pub struct DocumentsApproved { + pub user_id: GaloyUserId, +} + +impl NotificationEvent for DocumentsApproved { + fn user_id(&self) -> &GaloyUserId { + &self.user_id + } + + fn deep_link(&self) -> DeepLink { + DeepLink::None + } + + fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage { + Messages::documents_approved(locale.as_ref(), self) + } +} + +#[derive(Debug)] +pub struct DocumentsRejected { + pub user_id: GaloyUserId, +} + +impl NotificationEvent for DocumentsRejected { + fn user_id(&self) -> &GaloyUserId { + &self.user_id + } + + fn deep_link(&self) -> DeepLink { + DeepLink::None + } + + fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage { + Messages::documents_rejected(locale.as_ref(), self) + } +} + +#[derive(Debug)] +pub struct DocumentsReviewPending { + pub user_id: GaloyUserId, +} + +impl NotificationEvent for DocumentsReviewPending { + fn user_id(&self) -> &GaloyUserId { + &self.user_id + } + + fn deep_link(&self) -> DeepLink { + DeepLink::None + } + + fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage { + Messages::documents_review_pending(locale.as_ref(), self) + } +}