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 af3c498
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/api/dev/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,7 @@ enum NotificationCategoryAlt
@join__type(graph: NOTIFICATIONS)
{
CIRCLES @join__enumValue(graph: NOTIFICATIONS)
PAYMENTS @join__enumValue(graph: NOTIFICATIONS)
}

enum NotificationChannel
Expand Down
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
2 changes: 1 addition & 1 deletion core/notifications/src/cli/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn init_pool(config: &DbConfig) -> anyhow::Result<sqlx::PgPool> {
.connect(&config.pg_con)
.await?;

// sqlx::migrate!().run(&pool).await?;
sqlx::migrate!().run(&pool).await?;

Ok(pool)
}
Expand Down
1 change: 1 addition & 0 deletions core/notifications/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Mutation {

enum NotificationCategoryAlt {
CIRCLES
PAYMENTS
}

enum NotificationChannelAlt {
Expand Down
1 change: 1 addition & 0 deletions dev/config/apollo-federation/supergraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,7 @@ enum NotificationCategoryAlt
@join__type(graph: NOTIFICATIONS)
{
CIRCLES @join__enumValue(graph: NOTIFICATIONS)
PAYMENTS @join__enumValue(graph: NOTIFICATIONS)
}

enum NotificationChannel
Expand Down

0 comments on commit af3c498

Please sign in to comment.