Skip to content

Commit

Permalink
chore(notifications): more boilerplate for documents event
Browse files Browse the repository at this point in the history
  • Loading branch information
thevaibhav-dixit authored and bodymindarts committed Feb 12, 2024
1 parent c0ab329 commit 6e063a7
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/notifications/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
15 changes: 15 additions & 0 deletions core/notifications/proto/notifications.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
27 changes: 27 additions & 0 deletions core/notifications/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
36 changes: 36 additions & 0 deletions core/notifications/src/grpc/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
}

Expand Down
20 changes: 20 additions & 0 deletions core/notifications/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
57 changes: 57 additions & 0 deletions core/notifications/src/notification_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 6e063a7

Please sign in to comment.