Skip to content

Commit 6c725e9

Browse files
committed
fix: allow setting different default col for checkSort
1 parent 6fdb058 commit 6c725e9

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

backend/pkg/api/enums/notifications_enums.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (NotificationDashboardsColumn) NewFromString(s string) NotificationDashboar
2626
switch s {
2727
case "chain_id":
2828
return NotificationDashboardChainId
29-
case "epoch":
29+
case "", "epoch":
3030
return NotificationDashboardEpoch
3131
case "dashboard_name", "dashboard_id": // accepting id for frontend
3232
return NotificationDashboardDashboardName
@@ -98,7 +98,7 @@ func (NotificationMachinesColumn) NewFromString(s string) NotificationMachinesCo
9898
return NotificationMachineThreshold
9999
case "event_type":
100100
return NotificationMachineEventType
101-
case "timestamp":
101+
case "", "timestamp":
102102
return NotificationMachineTimestamp
103103
default:
104104
return NotificationMachinesColumn(-1)
@@ -157,7 +157,7 @@ func (NotificationClientsColumn) NewFromString(s string) NotificationClientsColu
157157
switch s {
158158
case "client_name":
159159
return NotificationClientName
160-
case "timestamp":
160+
case "", "timestamp":
161161
return NotificationClientTimestamp
162162
default:
163163
return NotificationClientsColumn(-1)
@@ -203,7 +203,7 @@ func (c NotificationRocketPoolColumn) Int() int {
203203

204204
func (NotificationRocketPoolColumn) NewFromString(s string) NotificationRocketPoolColumn {
205205
switch s {
206-
case "timestamp":
206+
case "", "timestamp":
207207
return NotificationRocketPoolTimestamp
208208
case "event_type":
209209
return NotificationRocketPoolEventType
@@ -243,7 +243,7 @@ func (c NotificationNetworksColumn) Int() int {
243243

244244
func (NotificationNetworksColumn) NewFromString(s string) NotificationNetworksColumn {
245245
switch s {
246-
case "timestamp":
246+
case "", "timestamp":
247247
return NotificationNetworkTimestamp
248248
case "event_type":
249249
return NotificationNetworkEventType
@@ -294,7 +294,7 @@ func (c NotificationSettingsDashboardColumn) Int() int {
294294

295295
func (NotificationSettingsDashboardColumn) NewFromString(s string) NotificationSettingsDashboardColumn {
296296
switch s {
297-
case "dashboard_name", "dashboard_id":
297+
case "", "dashboard_name", "dashboard_id":
298298
return NotificationSettingsDashboardDashboardName
299299
case "group_name":
300300
return NotificationSettingsDashboardGroupName

backend/pkg/api/enums/validator_dashboard_enums.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (c VDBSummaryColumn) Int() int {
2727

2828
func (VDBSummaryColumn) NewFromString(s string) VDBSummaryColumn {
2929
switch s {
30-
case "group_id":
30+
case "", "group_id":
3131
return VDBSummaryGroup
3232
case "validators":
3333
return VDBSummaryValidators
@@ -77,7 +77,7 @@ func (c VDBRewardsColumn) Int() int {
7777

7878
func (VDBRewardsColumn) NewFromString(s string) VDBRewardsColumn {
7979
switch s {
80-
case "epoch":
80+
case "", "epoch":
8181
return VDBRewardEpoch
8282
default:
8383
return VDBRewardsColumn(-1)
@@ -108,7 +108,7 @@ func (c VDBDutiesColumn) Int() int {
108108

109109
func (VDBDutiesColumn) NewFromString(s string) VDBDutiesColumn {
110110
switch s {
111-
case "validator":
111+
case "", "validator":
112112
return VDBDutyValidator
113113
case "reward":
114114
return VDBDutyReward
@@ -148,7 +148,7 @@ func (VDBBlocksColumn) NewFromString(s string) VDBBlocksColumn {
148148
switch s {
149149
case "proposer":
150150
return VDBBlockProposer
151-
case "slot":
151+
case "", "slot":
152152
return VDBBlockSlot
153153
case "block":
154154
return VDBBlockBlock
@@ -221,7 +221,7 @@ func (VDBWithdrawalsColumn) NewFromString(s string) VDBWithdrawalsColumn {
221221
switch s {
222222
case "epoch":
223223
return VDBWithdrawalEpoch
224-
case "slot":
224+
case "", "slot":
225225
return VDBWithdrawalSlot
226226
case "index":
227227
return VDBWithdrawalIndex
@@ -269,7 +269,7 @@ func (c VDBManageValidatorsColumn) Int() int {
269269

270270
func (VDBManageValidatorsColumn) NewFromString(s string) VDBManageValidatorsColumn {
271271
switch s {
272-
case "index":
272+
case "", "index":
273273
return VDBManageValidatorsIndex
274274
case "public_key":
275275
return VDBManageValidatorsPublicKey
@@ -409,7 +409,7 @@ func (c VDBRocketPoolColumn) Int() int {
409409

410410
func (VDBRocketPoolColumn) NewFromString(s string) VDBRocketPoolColumn {
411411
switch s {
412-
case "node":
412+
case "", "node":
413413
return VDBRocketPoolNode
414414
case "collateral":
415415
return VDBRocketPoolCollateral
@@ -473,7 +473,7 @@ func (c VDBRocketPoolMinipoolsColumn) Int() int {
473473

474474
func (VDBRocketPoolMinipoolsColumn) NewFromString(s string) VDBRocketPoolMinipoolsColumn {
475475
switch s {
476-
case "group_id":
476+
case "", "group_id":
477477
return VDBRocketPoolMinipoolsGroup
478478
default:
479479
return VDBRocketPoolMinipoolsColumn(-1)

backend/pkg/api/handlers/input_validation.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,11 @@ func (v *validationError) parseSortOrder(order string) bool {
378378
func checkSort[T enums.EnumFactory[T]](v *validationError, sortString string) *types.Sort[T] {
379379
var c T
380380
if sortString == "" {
381-
return &types.Sort[T]{Column: c, Desc: defaultDesc}
381+
sortCol := c.NewFromString(sortString)
382+
if enums.IsInvalidEnum(sortCol) {
383+
sortCol = c
384+
}
385+
return &types.Sort[T]{Column: sortCol, Desc: defaultDesc}
382386
}
383387
sortSplit := splitParameters(sortString, ':')
384388
if len(sortSplit) > 2 {

0 commit comments

Comments
 (0)