Skip to content

Commit 20d7cb4

Browse files
authored
Merge pull request #871 from gobitfly/BEDS-452
(BEDS-452) add client notification settings endpoint
2 parents 97bea08 + 434ccfc commit 20d7cb4

File tree

8 files changed

+123
-51
lines changed

8 files changed

+123
-51
lines changed

backend/pkg/api/data_access/dummy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ func (d *DummyService) UpdateNotificationSettingsPairedDevice(ctx context.Contex
486486
func (d *DummyService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error {
487487
return nil
488488
}
489+
490+
func (d *DummyService) UpdateNotificationSettingsClients(ctx context.Context, userId uint64, clientId uint64, IsSubscribed bool) (*t.NotificationSettingsClient, error) {
491+
return getDummyStruct[t.NotificationSettingsClient]()
492+
}
493+
489494
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) {
490495
r, p, err := getDummyWithPaging[t.NotificationSettingsDashboardsTableRow]()
491496
for i, n := range r {

backend/pkg/api/data_access/notifications.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type NotificationsRepository interface {
2525
UpdateNotificationSettingsNetworks(ctx context.Context, userId uint64, chainId uint64, settings t.NotificationSettingsNetwork) error
2626
UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string, name string, IsNotificationsEnabled bool) error
2727
DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error
28+
UpdateNotificationSettingsClients(ctx context.Context, userId uint64, clientId uint64, IsSubscribed bool) (*t.NotificationSettingsClient, error)
2829
GetNotificationSettingsDashboards(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationSettingsDashboardColumn], search string, limit uint64) ([]t.NotificationSettingsDashboardsTableRow, *t.Paging, error)
2930
UpdateNotificationSettingsValidatorDashboard(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, settings t.NotificationSettingsValidatorDashboard) error
3031
UpdateNotificationSettingsAccountDashboard(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, settings t.NotificationSettingsAccountDashboard) error
@@ -72,6 +73,9 @@ func (d *DataAccessService) UpdateNotificationSettingsPairedDevice(ctx context.C
7273
func (d *DataAccessService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error {
7374
return d.dummy.DeleteNotificationSettingsPairedDevice(ctx, userId, pairedDeviceId)
7475
}
76+
func (d *DataAccessService) UpdateNotificationSettingsClients(ctx context.Context, userId uint64, clientId uint64, IsSubscribed bool) (*t.NotificationSettingsClient, error) {
77+
return d.dummy.UpdateNotificationSettingsClients(ctx, userId, clientId, IsSubscribed)
78+
}
7579
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) {
7680
return d.dummy.GetNotificationSettingsDashboards(ctx, userId, cursor, colSort, search, limit)
7781
}

backend/pkg/api/handlers/internal.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ func (h *HandlerService) InternalDeleteUserNotificationSettingsPairedDevices(w h
609609
h.PublicDeleteUserNotificationSettingsPairedDevices(w, r)
610610
}
611611

612+
func (h *HandlerService) InternalPutUserNotificationSettingsClient(w http.ResponseWriter, r *http.Request) {
613+
h.PublicPutUserNotificationSettingsClient(w, r)
614+
}
615+
612616
func (h *HandlerService) InternalGetUserNotificationSettingsDashboards(w http.ResponseWriter, r *http.Request) {
613617
h.PublicGetUserNotificationSettingsDashboards(w, r)
614618
}

backend/pkg/api/handlers/public.go

Lines changed: 82 additions & 40 deletions
Large diffs are not rendered by default.

backend/pkg/api/router.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ func addNotificationRoutes(hs *handlers.HandlerService, publicRouter, internalRo
331331
{http.MethodPut, "/settings/networks/{network}", hs.PublicPutUserNotificationSettingsNetworks, hs.InternalPutUserNotificationSettingsNetworks},
332332
{http.MethodPut, "/settings/paired-devices/{paired_device_id}", hs.PublicPutUserNotificationSettingsPairedDevices, hs.InternalPutUserNotificationSettingsPairedDevices},
333333
{http.MethodDelete, "/settings/paired-devices/{paired_device_id}", hs.PublicDeleteUserNotificationSettingsPairedDevices, hs.InternalDeleteUserNotificationSettingsPairedDevices},
334+
{http.MethodPut, "/settings/clients/{client_id}", hs.PublicPutUserNotificationSettingsClient, hs.InternalPutUserNotificationSettingsClient},
334335
{http.MethodGet, "/settings/dashboards", hs.PublicGetUserNotificationSettingsDashboards, hs.InternalGetUserNotificationSettingsDashboards},
335336
{http.MethodPost, "/test-email", hs.PublicPostUserNotificationsTestEmail, hs.InternalPostUserNotificationsTestEmail},
336337
{http.MethodPost, "/test-push", hs.PublicPostUserNotificationsTestPush, hs.InternalPostUserNotificationsTestPush},

backend/pkg/api/types/notifications.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ type NotificationPairedDevice struct {
163163
}
164164
type InternalPutUserNotificationSettingsPairedDevicesResponse ApiDataResponse[NotificationPairedDevice]
165165

166+
type NotificationSettingsClient struct {
167+
Id uint64 `json:"id"`
168+
Name string `json:"name"`
169+
Category string `json:"category"`
170+
IsSubscribed bool `json:"is_subscribed"`
171+
}
172+
173+
type InternalPutUserNotificationSettingsClientResponse ApiDataResponse[NotificationSettingsClient]
174+
166175
type NotificationSettingsGeneral struct {
167176
DoNotDisturbTimestamp int64 `json:"do_not_disturb_timestamp"` // notifications are disabled until this timestamp
168177
IsEmailNotificationsEnabled bool `json:"is_email_notifications_enabled"`
@@ -176,18 +185,18 @@ type NotificationSettingsGeneral struct {
176185
IsMachineMemoryUsageSubscribed bool `json:"is_machine_memory_usage_subscribed"`
177186
MachineMemoryUsageThreshold float64 `json:"machine_memory_usage_threshold" faker:"boundary_start=0, boundary_end=1"`
178187

179-
SubscribedClients []string `json:"subscribed_clients"`
180-
IsRocketPoolNewRewardRoundSubscribed bool `json:"is_rocket_pool_new_reward_round_subscribed"`
181-
IsRocketPoolMaxCollateralSubscribed bool `json:"is_rocket_pool_max_collateral_subscribed"`
182-
RocketPoolMaxCollateralThreshold float64 `json:"rocket_pool_max_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
183-
IsRocketPoolMinCollateralSubscribed bool `json:"is_rocket_pool_min_collateral_subscribed"`
184-
RocketPoolMinCollateralThreshold float64 `json:"rocket_pool_min_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
188+
IsRocketPoolNewRewardRoundSubscribed bool `json:"is_rocket_pool_new_reward_round_subscribed"`
189+
IsRocketPoolMaxCollateralSubscribed bool `json:"is_rocket_pool_max_collateral_subscribed"`
190+
RocketPoolMaxCollateralThreshold float64 `json:"rocket_pool_max_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
191+
IsRocketPoolMinCollateralSubscribed bool `json:"is_rocket_pool_min_collateral_subscribed"`
192+
RocketPoolMinCollateralThreshold float64 `json:"rocket_pool_min_collateral_threshold" faker:"boundary_start=0, boundary_end=1"`
185193
}
186194
type InternalPutUserNotificationSettingsGeneralResponse ApiDataResponse[NotificationSettingsGeneral]
187195
type NotificationSettings struct {
188-
GeneralSettings NotificationSettingsGeneral `json:"general_settings"`
189-
Networks []NotificationNetwork `json:"networks"`
190-
PairedDevices []NotificationPairedDevice `json:"paired_devices"`
196+
GeneralSettings NotificationSettingsGeneral `json:"general_settings"`
197+
Networks []NotificationNetwork `json:"networks"`
198+
PairedDevices []NotificationPairedDevice `json:"paired_devices"`
199+
Clients []NotificationSettingsClient `json:"clients"`
191200
}
192201
type InternalGetUserNotificationSettingsResponse ApiDataResponse[NotificationSettings]
193202

frontend/stores/notifications/useNotificationsManagementStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const useNotificationsManagementStore = defineStore('notifications-manage
1010
const { fetch } = useCustomFetch()
1111
const settings = ref<NotificationSettings>(
1212
{
13+
clients: [],
1314
general_settings: {
1415
do_not_disturb_timestamp: 0,
1516
is_email_notifications_enabled: false,
@@ -26,7 +27,6 @@ export const useNotificationsManagementStore = defineStore('notifications-manage
2627
machine_storage_usage_threshold: 0.0,
2728
rocket_pool_max_collateral_threshold: 0,
2829
rocket_pool_min_collateral_threshold: 0,
29-
subscribed_clients: [],
3030
},
3131
networks: [ {
3232
chain_id: 0,

frontend/types/api/notifications.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ export interface NotificationPairedDevice {
157157
is_notifications_enabled: boolean;
158158
}
159159
export type InternalPutUserNotificationSettingsPairedDevicesResponse = ApiDataResponse<NotificationPairedDevice>;
160+
export interface NotificationSettingsClient {
161+
id: number /* uint64 */;
162+
name: string;
163+
category: string;
164+
is_subscribed: boolean;
165+
}
166+
export type InternalPutUserNotificationSettingsClientResponse = ApiDataResponse<NotificationSettingsClient>;
160167
export interface NotificationSettingsGeneral {
161168
do_not_disturb_timestamp: number /* int64 */; // notifications are disabled until this timestamp
162169
is_email_notifications_enabled: boolean;
@@ -168,7 +175,6 @@ export interface NotificationSettingsGeneral {
168175
machine_cpu_usage_threshold: number /* float64 */;
169176
is_machine_memory_usage_subscribed: boolean;
170177
machine_memory_usage_threshold: number /* float64 */;
171-
subscribed_clients: string[];
172178
is_rocket_pool_new_reward_round_subscribed: boolean;
173179
is_rocket_pool_max_collateral_subscribed: boolean;
174180
rocket_pool_max_collateral_threshold: number /* float64 */;
@@ -180,6 +186,7 @@ export interface NotificationSettings {
180186
general_settings: NotificationSettingsGeneral;
181187
networks: NotificationNetwork[];
182188
paired_devices: NotificationPairedDevice[];
189+
clients: NotificationSettingsClient[];
183190
}
184191
export type InternalGetUserNotificationSettingsResponse = ApiDataResponse<NotificationSettings>;
185192
export interface NotificationSettingsValidatorDashboard {

0 commit comments

Comments
 (0)