-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(notifications): some settings entity boilerplate
- Loading branch information
1 parent
00aaf24
commit f631835
Showing
12 changed files
with
154 additions
and
26 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...cations/.sqlx/query-94f56f9bf9625b0109f038f4157d3f3a3ef55c10681f8d4e0606e4c24c8259f4.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
core/notifications/migrations/20240111102028_notifications_setup.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CREATE TABLE account_notification_settings ( | ||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | ||
galoy_account_id VARCHAR UNIQUE NOT NULL, | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
); | ||
|
||
CREATE TABLE account_notification_settings_events ( | ||
id UUID REFERENCES account_notification_settings(id) NOT NULL, | ||
sequence INT NOT NULL, | ||
event_type VARCHAR NOT NULL, | ||
event JSONB NOT NULL, | ||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
UNIQUE(id, sequence) | ||
); |
9 changes: 9 additions & 0 deletions
9
core/notifications/src/account_notification_settings/error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum AccountNotificationSettingsError { | ||
#[error("AccountNotificationSettingsError - Sqlx: {0}")] | ||
Sqlx(#[from] sqlx::Error), | ||
#[error("AccountNotificationSettingsError - EntityError: {0}")] | ||
EntityError(#[from] es_entity::EntityError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
mod entity; | ||
// mod value; | ||
pub mod error; | ||
mod repo; | ||
|
||
pub use entity::*; | ||
// pub use entity::*; | ||
pub use repo::*; |
39 changes: 39 additions & 0 deletions
39
core/notifications/src/account_notification_settings/repo.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use sqlx::PgPool; | ||
|
||
use es_entity::*; | ||
|
||
use super::{entity::*, error::*}; | ||
use crate::primitives::*; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct AccountNotificationSettingsRepo { | ||
pool: PgPool, | ||
} | ||
|
||
impl AccountNotificationSettingsRepo { | ||
pub fn new(pool: &PgPool) -> Self { | ||
Self { pool: pool.clone() } | ||
} | ||
|
||
pub async fn find_for_account_id( | ||
&self, | ||
account_id: GaloyAccountId, | ||
) -> Result<Option<AccountNotificationSettings>, AccountNotificationSettingsError> { | ||
let rows = sqlx::query_as!( | ||
GenericEvent, | ||
r#"SELECT a.id, e.sequence, e.event | ||
FROM account_notification_settings a | ||
JOIN account_notification_settings_events e ON a.id = e.id | ||
WHERE a.galoy_account_id = $1 | ||
ORDER BY e.sequence"#, | ||
account_id.as_ref(), | ||
) | ||
.fetch_all(&self.pool) | ||
.await?; | ||
let res = EntityEvents::load_first::<AccountNotificationSettings>(rows); | ||
if matches!(res, Err(EntityError::NoEntityEventsPresent)) { | ||
return Ok(None); | ||
} | ||
Ok(Some(res?)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
use thiserror::Error; | ||
|
||
use crate::account_notification_settings::error::*; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum ApplicationError {} | ||
pub enum ApplicationError { | ||
#[error("{0}")] | ||
AccountNotificationSettingsError(#[from] AccountNotificationSettingsError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,14 @@ | ||
use async_graphql::*; | ||
|
||
use crate::primitives::*; | ||
|
||
#[derive(SimpleObject)] | ||
pub(super) struct NotificationSettingsAlt { | ||
pub push: NotificationChannelSettingsAlt, | ||
} | ||
|
||
#[derive(Enum, Copy, Clone, Eq, PartialEq)] | ||
pub(super) enum NotificationCategoryAlt { | ||
Circles, | ||
} | ||
|
||
#[derive(SimpleObject)] | ||
pub(super) struct NotificationChannelSettingsAlt { | ||
pub enabled: bool, | ||
pub disabled_categories: Vec<NotificationCategoryAlt>, | ||
} | ||
|
||
#[derive(Enum, Copy, Clone, Eq, PartialEq)] | ||
pub(super) enum NotificationChannelAlt { | ||
Push, | ||
pub disabled_categories: Vec<NotificationCategory>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters