Skip to content

Commit

Permalink
refactor(notifications): unify handling of notification events in app
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Feb 12, 2024
1 parent 6e063a7 commit 177c1df
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 52 deletions.
48 changes: 3 additions & 45 deletions core/notifications/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,52 +149,10 @@ impl NotificationsApp {
Ok(user_settings)
}

#[instrument(name = "app.handle_circle_grew", skip(self), err)]
pub async fn handle_circle_grew(&self, event: CircleGrew) -> Result<(), ApplicationError> {
self.executor.notify(event).await?;
Ok(())
}

#[instrument(name = "app.handle_threshold_reached", skip(self), err)]
pub async fn handle_threshold_reached(
&self,
event: CircleThresholdReached,
) -> Result<(), ApplicationError> {
self.executor.notify(event).await?;
Ok(())
}

#[instrument(name = "app.handle_documents_submitted", skip(self), err)]
pub async fn handle_documents_submitted(
&self,
event: DocumentsSubmitted,
) -> Result<(), ApplicationError> {
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(
#[instrument(name = "app.handle_notification_event", skip(self), err)]
pub async fn handle_notification_event<T: NotificationEvent>(
&self,
event: DocumentsReviewPending,
event: T,
) -> Result<(), ApplicationError> {
self.executor.notify(event).await?;
Ok(())
Expand Down
12 changes: 6 additions & 6 deletions core/notifications/src/grpc/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl NotificationsService for Notifications {
.map(primitives::CircleType::from)
.map_err(|e| Status::invalid_argument(e.to_string()))?;
self.app
.handle_circle_grew(notification_event::CircleGrew {
.handle_notification_event(notification_event::CircleGrew {
user_id: GaloyUserId::from(user_id),
circle_type,
this_month_circle_size,
Expand All @@ -277,7 +277,7 @@ impl NotificationsService for Notifications {
.map(primitives::CircleTimeFrame::from)
.map_err(|e| Status::invalid_argument(e.to_string()))?;
self.app
.handle_threshold_reached(notification_event::CircleThresholdReached {
.handle_notification_event(notification_event::CircleThresholdReached {
user_id: GaloyUserId::from(user_id),
circle_type,
time_frame,
Expand All @@ -292,7 +292,7 @@ impl NotificationsService for Notifications {
)),
}) => {
self.app
.handle_documents_submitted(notification_event::DocumentsSubmitted {
.handle_notification_event(notification_event::DocumentsSubmitted {
user_id: GaloyUserId::from(user_id),
})
.await?
Expand All @@ -304,7 +304,7 @@ impl NotificationsService for Notifications {
})),
}) => {
self.app
.handle_documents_approved(notification_event::DocumentsApproved {
.handle_notification_event(notification_event::DocumentsApproved {
user_id: GaloyUserId::from(user_id),
})
.await?
Expand All @@ -316,7 +316,7 @@ impl NotificationsService for Notifications {
})),
}) => {
self.app
.handle_documents_rejected(notification_event::DocumentsRejected {
.handle_notification_event(notification_event::DocumentsRejected {
user_id: GaloyUserId::from(user_id),
})
.await?
Expand All @@ -328,7 +328,7 @@ impl NotificationsService for Notifications {
)),
}) => {
self.app
.handle_documents_review_pending(notification_event::DocumentsReviewPending {
.handle_notification_event(notification_event::DocumentsReviewPending {
user_id: GaloyUserId::from(user_id),
})
.await?
Expand Down
2 changes: 1 addition & 1 deletion core/notifications/src/notification_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct CircleGrew {
pub all_time_circle_size: u32,
}

pub trait NotificationEvent {
pub trait NotificationEvent: std::fmt::Debug {
fn user_id(&self) -> &GaloyUserId;
fn deep_link(&self) -> DeepLink;
fn to_localized_msg(&self, locale: GaloyLocale) -> LocalizedMessage;
Expand Down

0 comments on commit 177c1df

Please sign in to comment.