Skip to content

Commit

Permalink
Merge pull request #871 from gobitfly/BEDS-452
Browse files Browse the repository at this point in the history
(BEDS-452) add client notification settings endpoint
  • Loading branch information
remoterami authored Sep 27, 2024
2 parents 97bea08 + 434ccfc commit 20d7cb4
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 51 deletions.
5 changes: 5 additions & 0 deletions backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ func (d *DummyService) UpdateNotificationSettingsPairedDevice(ctx context.Contex
func (d *DummyService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error {
return nil
}

func (d *DummyService) UpdateNotificationSettingsClients(ctx context.Context, userId uint64, clientId uint64, IsSubscribed bool) (*t.NotificationSettingsClient, error) {
return getDummyStruct[t.NotificationSettingsClient]()
}

func (d *DummyService) GetNotificationSettingsDashboards(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationSettingsDashboardColumn], search string, limit uint64) ([]t.NotificationSettingsDashboardsTableRow, *t.Paging, error) {
r, p, err := getDummyWithPaging[t.NotificationSettingsDashboardsTableRow]()
for i, n := range r {
Expand Down
4 changes: 4 additions & 0 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type NotificationsRepository interface {
UpdateNotificationSettingsNetworks(ctx context.Context, userId uint64, chainId uint64, settings t.NotificationSettingsNetwork) error
UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string, name string, IsNotificationsEnabled bool) error
DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error
UpdateNotificationSettingsClients(ctx context.Context, userId uint64, clientId uint64, IsSubscribed bool) (*t.NotificationSettingsClient, error)
GetNotificationSettingsDashboards(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationSettingsDashboardColumn], search string, limit uint64) ([]t.NotificationSettingsDashboardsTableRow, *t.Paging, error)
UpdateNotificationSettingsValidatorDashboard(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, settings t.NotificationSettingsValidatorDashboard) error
UpdateNotificationSettingsAccountDashboard(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, settings t.NotificationSettingsAccountDashboard) error
Expand Down Expand Up @@ -72,6 +73,9 @@ func (d *DataAccessService) UpdateNotificationSettingsPairedDevice(ctx context.C
func (d *DataAccessService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error {
return d.dummy.DeleteNotificationSettingsPairedDevice(ctx, userId, pairedDeviceId)
}
func (d *DataAccessService) UpdateNotificationSettingsClients(ctx context.Context, userId uint64, clientId uint64, IsSubscribed bool) (*t.NotificationSettingsClient, error) {
return d.dummy.UpdateNotificationSettingsClients(ctx, userId, clientId, IsSubscribed)
}
func (d *DataAccessService) GetNotificationSettingsDashboards(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationSettingsDashboardColumn], search string, limit uint64) ([]t.NotificationSettingsDashboardsTableRow, *t.Paging, error) {
return d.dummy.GetNotificationSettingsDashboards(ctx, userId, cursor, colSort, search, limit)
}
Expand Down
4 changes: 4 additions & 0 deletions backend/pkg/api/handlers/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ func (h *HandlerService) InternalDeleteUserNotificationSettingsPairedDevices(w h
h.PublicDeleteUserNotificationSettingsPairedDevices(w, r)
}

func (h *HandlerService) InternalPutUserNotificationSettingsClient(w http.ResponseWriter, r *http.Request) {
h.PublicPutUserNotificationSettingsClient(w, r)
}

func (h *HandlerService) InternalGetUserNotificationSettingsDashboards(w http.ResponseWriter, r *http.Request) {
h.PublicGetUserNotificationSettingsDashboards(w, r)
}
Expand Down
122 changes: 82 additions & 40 deletions backend/pkg/api/handlers/public.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/pkg/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ func addNotificationRoutes(hs *handlers.HandlerService, publicRouter, internalRo
{http.MethodPut, "/settings/networks/{network}", hs.PublicPutUserNotificationSettingsNetworks, hs.InternalPutUserNotificationSettingsNetworks},
{http.MethodPut, "/settings/paired-devices/{paired_device_id}", hs.PublicPutUserNotificationSettingsPairedDevices, hs.InternalPutUserNotificationSettingsPairedDevices},
{http.MethodDelete, "/settings/paired-devices/{paired_device_id}", hs.PublicDeleteUserNotificationSettingsPairedDevices, hs.InternalDeleteUserNotificationSettingsPairedDevices},
{http.MethodPut, "/settings/clients/{client_id}", hs.PublicPutUserNotificationSettingsClient, hs.InternalPutUserNotificationSettingsClient},
{http.MethodGet, "/settings/dashboards", hs.PublicGetUserNotificationSettingsDashboards, hs.InternalGetUserNotificationSettingsDashboards},
{http.MethodPost, "/test-email", hs.PublicPostUserNotificationsTestEmail, hs.InternalPostUserNotificationsTestEmail},
{http.MethodPost, "/test-push", hs.PublicPostUserNotificationsTestPush, hs.InternalPostUserNotificationsTestPush},
Expand Down
27 changes: 18 additions & 9 deletions backend/pkg/api/types/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ type NotificationPairedDevice struct {
}
type InternalPutUserNotificationSettingsPairedDevicesResponse ApiDataResponse[NotificationPairedDevice]

type NotificationSettingsClient struct {
Id uint64 `json:"id"`
Name string `json:"name"`
Category string `json:"category"`
IsSubscribed bool `json:"is_subscribed"`
}

type InternalPutUserNotificationSettingsClientResponse ApiDataResponse[NotificationSettingsClient]

type NotificationSettingsGeneral struct {
DoNotDisturbTimestamp int64 `json:"do_not_disturb_timestamp"` // notifications are disabled until this timestamp
IsEmailNotificationsEnabled bool `json:"is_email_notifications_enabled"`
Expand All @@ -176,18 +185,18 @@ type NotificationSettingsGeneral struct {
IsMachineMemoryUsageSubscribed bool `json:"is_machine_memory_usage_subscribed"`
MachineMemoryUsageThreshold float64 `json:"machine_memory_usage_threshold" faker:"boundary_start=0, boundary_end=1"`

SubscribedClients []string `json:"subscribed_clients"`
IsRocketPoolNewRewardRoundSubscribed bool `json:"is_rocket_pool_new_reward_round_subscribed"`
IsRocketPoolMaxCollateralSubscribed bool `json:"is_rocket_pool_max_collateral_subscribed"`
RocketPoolMaxCollateralThreshold float64 `json:"rocket_pool_max_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
IsRocketPoolMinCollateralSubscribed bool `json:"is_rocket_pool_min_collateral_subscribed"`
RocketPoolMinCollateralThreshold float64 `json:"rocket_pool_min_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
IsRocketPoolNewRewardRoundSubscribed bool `json:"is_rocket_pool_new_reward_round_subscribed"`
IsRocketPoolMaxCollateralSubscribed bool `json:"is_rocket_pool_max_collateral_subscribed"`
RocketPoolMaxCollateralThreshold float64 `json:"rocket_pool_max_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
IsRocketPoolMinCollateralSubscribed bool `json:"is_rocket_pool_min_collateral_subscribed"`
RocketPoolMinCollateralThreshold float64 `json:"rocket_pool_min_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
}
type InternalPutUserNotificationSettingsGeneralResponse ApiDataResponse[NotificationSettingsGeneral]
type NotificationSettings struct {
GeneralSettings NotificationSettingsGeneral `json:"general_settings"`
Networks []NotificationNetwork `json:"networks"`
PairedDevices []NotificationPairedDevice `json:"paired_devices"`
GeneralSettings NotificationSettingsGeneral `json:"general_settings"`
Networks []NotificationNetwork `json:"networks"`
PairedDevices []NotificationPairedDevice `json:"paired_devices"`
Clients []NotificationSettingsClient `json:"clients"`
}
type InternalGetUserNotificationSettingsResponse ApiDataResponse[NotificationSettings]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const useNotificationsManagementStore = defineStore('notifications-manage
const { fetch } = useCustomFetch()
const settings = ref<NotificationSettings>(
{
clients: [],
general_settings: {
do_not_disturb_timestamp: 0,
is_email_notifications_enabled: false,
Expand All @@ -26,7 +27,6 @@ export const useNotificationsManagementStore = defineStore('notifications-manage
machine_storage_usage_threshold: 0.0,
rocket_pool_max_collateral_threshold: 0,
rocket_pool_min_collateral_threshold: 0,
subscribed_clients: [],
},
networks: [ {
chain_id: 0,
Expand Down
9 changes: 8 additions & 1 deletion frontend/types/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ export interface NotificationPairedDevice {
is_notifications_enabled: boolean;
}
export type InternalPutUserNotificationSettingsPairedDevicesResponse = ApiDataResponse<NotificationPairedDevice>;
export interface NotificationSettingsClient {
id: number /* uint64 */;
name: string;
category: string;
is_subscribed: boolean;
}
export type InternalPutUserNotificationSettingsClientResponse = ApiDataResponse<NotificationSettingsClient>;
export interface NotificationSettingsGeneral {
do_not_disturb_timestamp: number /* int64 */; // notifications are disabled until this timestamp
is_email_notifications_enabled: boolean;
Expand All @@ -168,7 +175,6 @@ export interface NotificationSettingsGeneral {
machine_cpu_usage_threshold: number /* float64 */;
is_machine_memory_usage_subscribed: boolean;
machine_memory_usage_threshold: number /* float64 */;
subscribed_clients: string[];
is_rocket_pool_new_reward_round_subscribed: boolean;
is_rocket_pool_max_collateral_subscribed: boolean;
rocket_pool_max_collateral_threshold: number /* float64 */;
Expand All @@ -180,6 +186,7 @@ export interface NotificationSettings {
general_settings: NotificationSettingsGeneral;
networks: NotificationNetwork[];
paired_devices: NotificationPairedDevice[];
clients: NotificationSettingsClient[];
}
export type InternalGetUserNotificationSettingsResponse = ApiDataResponse<NotificationSettings>;
export interface NotificationSettingsValidatorDashboard {
Expand Down

0 comments on commit 20d7cb4

Please sign in to comment.