Skip to content

Commit

Permalink
Changed device identifier to id
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisei24 committed Oct 22, 2024
1 parent c364333 commit 7379918
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,10 @@ func (d *DummyService) UpdateNotificationSettingsGeneral(ctx context.Context, us
func (d *DummyService) UpdateNotificationSettingsNetworks(ctx context.Context, userId uint64, chainId uint64, settings t.NotificationSettingsNetwork) error {
return nil
}
func (d *DummyService) UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string, name string, IsNotificationsEnabled bool) error {
func (d *DummyService) UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64, name string, IsNotificationsEnabled bool) error {
return nil
}
func (d *DummyService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error {
func (d *DummyService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64) error {
return nil
}

Expand Down
30 changes: 15 additions & 15 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ type NotificationsRepository interface {
GetNotificationSettingsDefaultValues(ctx context.Context) (*t.NotificationSettingsDefaultValues, error)
UpdateNotificationSettingsGeneral(ctx context.Context, userId uint64, settings t.NotificationSettingsGeneral) error
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
UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64, name string, IsNotificationsEnabled bool) error
DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64) 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, userId uint64, dashboardId t.VDBIdPrimary, groupId uint64, settings t.NotificationSettingsValidatorDashboard) error
Expand Down Expand Up @@ -1325,20 +1325,20 @@ func (d *DataAccessService) GetNotificationSettings(ctx context.Context, userId
// -------------------------------------
// Get the paired devices
pairedDevices := []struct {
DeviceIdentifier sql.NullString `db:"device_identifier"`
CreatedTs time.Time `db:"created_ts"`
DeviceName string `db:"device_name"`
NotifyEnabled bool `db:"notify_enabled"`
DeviceId uint64 `db:"id"`
CreatedTs time.Time `db:"created_ts"`
DeviceName string `db:"device_name"`
NotifyEnabled bool `db:"notify_enabled"`
}{}
wg.Go(func() error {
err := d.userReader.SelectContext(ctx, &pairedDevices, `
SELECT
device_identifier,
id,
created_ts,
device_name,
COALESCE(notify_enabled, false) AS notify_enabled
FROM users_devices
WHERE user_id = $1 AND device_identifier IS NOT NULL`, userId)
WHERE user_id = $1`, userId)
if err != nil {
return fmt.Errorf(`error retrieving data for notifications paired devices: %w`, err)
}
Expand Down Expand Up @@ -1429,7 +1429,7 @@ func (d *DataAccessService) GetNotificationSettings(ctx context.Context, userId

for _, device := range pairedDevices {
result.PairedDevices = append(result.PairedDevices, t.NotificationPairedDevice{
Id: device.DeviceIdentifier.String,
Id: device.DeviceId,
PairedTimestamp: device.CreatedTs.Unix(),
Name: device.DeviceName,
IsNotificationsEnabled: device.NotifyEnabled,
Expand Down Expand Up @@ -1642,13 +1642,13 @@ func (d *DataAccessService) UpdateNotificationSettingsNetworks(ctx context.Conte
}
return nil
}
func (d *DataAccessService) UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string, name string, IsNotificationsEnabled bool) error {
func (d *DataAccessService) UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64, name string, IsNotificationsEnabled bool) error {
result, err := d.userWriter.ExecContext(ctx, `
UPDATE users_devices
SET
device_name = $1,
notify_enabled = $2
WHERE user_id = $3 AND device_identifier = $4`,
WHERE user_id = $3 AND id = $4`,
name, IsNotificationsEnabled, userId, pairedDeviceId)
if err != nil {
return err
Expand All @@ -1660,14 +1660,14 @@ func (d *DataAccessService) UpdateNotificationSettingsPairedDevice(ctx context.C
return err
}
if rowsAffected == 0 {
return fmt.Errorf("device with id %s to update notification settings not found", pairedDeviceId)
return fmt.Errorf("device with id %v to update notification settings not found", pairedDeviceId)
}
return nil
}
func (d *DataAccessService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error {
func (d *DataAccessService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64) error {
result, err := d.userWriter.ExecContext(ctx, `
DELETE FROM users_devices
WHERE user_id = $1 AND device_identifier = $2`,
WHERE user_id = $1 AND id = $2`,
userId, pairedDeviceId)
if err != nil {
return err
Expand All @@ -1679,7 +1679,7 @@ func (d *DataAccessService) DeleteNotificationSettingsPairedDevice(ctx context.C
return err
}
if rowsAffected == 0 {
return fmt.Errorf("device with id %s to delete not found", pairedDeviceId)
return fmt.Errorf("device with id %v to delete not found", pairedDeviceId)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/api/handlers/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ func (h *HandlerService) PublicPutUserNotificationSettingsPairedDevices(w http.R
return
}
// TODO use a better way to validate the paired device id
pairedDeviceId := v.checkRegex(reNonEmpty, mux.Vars(r)["paired_device_id"], "paired_device_id")
pairedDeviceId := v.checkUint(mux.Vars(r)["paired_device_id"], "paired_device_id")
name := v.checkNameNotEmpty(req.Name)
if v.hasErrors() {
handleErr(w, r, v)
Expand Down Expand Up @@ -2386,7 +2386,7 @@ func (h *HandlerService) PublicDeleteUserNotificationSettingsPairedDevices(w htt
return
}
// TODO use a better way to validate the paired device id
pairedDeviceId := v.checkRegex(reNonEmpty, mux.Vars(r)["paired_device_id"], "paired_device_id")
pairedDeviceId := v.checkUint(mux.Vars(r)["paired_device_id"], "paired_device_id")
if v.hasErrors() {
handleErr(w, r, v)
return
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/api/types/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ type NotificationNetwork struct {
type InternalPutUserNotificationSettingsNetworksResponse ApiDataResponse[NotificationNetwork]

type NotificationPairedDevice struct {
Id string `json:"id"`
Id uint64 `json:"id"`
PairedTimestamp int64 `json:"paired_timestamp"`
Name string `json:"name,omitempty"`
IsNotificationsEnabled bool `json:"is_notifications_enabled"`
Expand Down
2 changes: 1 addition & 1 deletion frontend/types/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export interface NotificationNetwork {
}
export type InternalPutUserNotificationSettingsNetworksResponse = ApiDataResponse<NotificationNetwork>;
export interface NotificationPairedDevice {
id: string;
id: number /* uint64 */;
paired_timestamp: number /* int64 */;
name?: string;
is_notifications_enabled: boolean;
Expand Down

0 comments on commit 7379918

Please sign in to comment.