Skip to content

Commit

Permalink
chore(notifications): complete initial use case e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Jan 11, 2024
1 parent a62bd40 commit 0e11504
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
12 changes: 12 additions & 0 deletions core/notifications/src/account_notification_settings/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ impl EsEntity for AccountNotificationSettings {
}

impl AccountNotificationSettings {
pub fn new(galoy_account_id: GaloyAccountId) -> Self {
let id = AccountNotificationSettingsId::new();
Self::try_from(EntityEvents::init(
id,
[AccountNotificationSettingsEvent::Initialized {
id,
galoy_account_id,
}],
))
.expect("Could not create default")
}

pub fn disable_channel(&mut self, channel: NotificationChannel) {
if !self.is_channel_enabled(channel) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl AccountNotificationSettingsRepo {

pub async fn find_for_account_id(
&self,
account_id: GaloyAccountId,
account_id: &GaloyAccountId,
) -> Result<Option<AccountNotificationSettings>, AccountNotificationSettingsError> {
let rows = sqlx::query_as!(
GenericEvent,
Expand Down
5 changes: 2 additions & 3 deletions core/notifications/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ impl NotificationsApp {
channel: NotificationChannel,
) -> Result<AccountNotificationSettings, ApplicationError> {
let mut account_settings =
if let Some(settings) = self.settings.find_for_account_id(account_id).await? {
if let Some(settings) = self.settings.find_for_account_id(&account_id).await? {
settings
} else {
unimplemented!()
// AccountNotificationSettings::default()
AccountNotificationSettings::new(account_id)
};
account_settings.disable_channel(channel);
self.settings.persist(&mut account_settings).await?;
Expand Down

0 comments on commit 0e11504

Please sign in to comment.