Skip to content

Commit

Permalink
change validators param for data access funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
LuccaBitfly committed Mar 6, 2024
1 parent d168df7 commit d16ae3e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
15 changes: 11 additions & 4 deletions backend/pkg/api/data_access/data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

type DataAccessInterface interface {
GetUserDashboards(userId uint64) (t.UserDashboardsData, error)
GetValidatorsFromStrings(validators []string) ([]t.VDBValidator, error)

CreateValidatorDashboard(userId uint64, name string, network uint64) (t.VDBPostReturnData, error)
RemoveValidatorDashboard(dashboardId t.VDBIdPrimary) error
Expand All @@ -34,8 +35,8 @@ type DataAccessInterface interface {
CreateValidatorDashboardGroup(dashboardId t.VDBIdPrimary, name string) (t.VDBOverviewGroup, error)
RemoveValidatorDashboardGroup(dashboardId t.VDBIdPrimary, groupId uint64) error

AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []string) ([]t.VDBPostValidatorsData, error)
RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []string) error
AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error)
RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) error
GetValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, cursor string, sort []t.Sort[enums.VDBManageValidatorsColumn], search string, limit uint64) ([]t.VDBManageValidatorsTableRow, t.Paging, error)
GetValidatorDashboardValidatorsByPublicId(dashboardId t.VDBIdPublic, groupId uint64, cursor string, sort []t.Sort[enums.VDBManageValidatorsColumn], search string, limit uint64) ([]t.VDBManageValidatorsTableRow, t.Paging, error)
GetValidatorDashboardValidatorsByValidators(dashboardId t.VDBIdValidatorSet, cursor string, sort []t.Sort[enums.VDBManageValidatorsColumn], search string, limit uint64) ([]t.VDBManageValidatorsTableRow, t.Paging, error)
Expand Down Expand Up @@ -205,6 +206,12 @@ func (d DataAccessService) GetUserDashboards(userId uint64) (t.UserDashboardsDat
return d.dummy.GetUserDashboards(userId)
}

// param validators: slice of validator public keys or indices, a index should resolve to the newest index version
func (d DataAccessService) GetValidatorsFromStrings(validators []string) ([]t.VDBValidator, error) {
// TODO @recy21
return d.dummy.GetValidatorsFromStrings(validators)
}

func (d DataAccessService) CreateValidatorDashboard(userId uint64, name string, network uint64) (t.VDBPostReturnData, error) {
return d.dummy.CreateValidatorDashboard(userId, name, network)
}
Expand Down Expand Up @@ -254,7 +261,7 @@ func (d DataAccessService) RemoveValidatorDashboardGroup(dashboardId t.VDBIdPrim
return d.dummy.RemoveValidatorDashboardGroup(dashboardId, groupId)
}

func (d DataAccessService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []string) ([]t.VDBPostValidatorsData, error) {
func (d DataAccessService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) {
// TODO @recy21
return d.dummy.AddValidatorDashboardValidators(dashboardId, groupId, validators)
}
Expand All @@ -274,7 +281,7 @@ func (d DataAccessService) GetValidatorDashboardValidatorsByValidators(dashboard
return d.dummy.GetValidatorDashboardValidatorsByValidators(dashboardId, cursor, sort, search, limit)
}

func (d DataAccessService) RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []string) error {
func (d DataAccessService) RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) error {
// TODO @recy21
return d.dummy.RemoveValidatorDashboardValidators(dashboardId, validators)
}
Expand Down
10 changes: 8 additions & 2 deletions backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func (d DummyService) GetUserDashboards(userId uint64) (t.UserDashboardsData, er
return r, err
}

func (d DummyService) GetValidatorsFromStrings(validators []string) ([]t.VDBValidator, error) {
r := []t.VDBValidator{}
err := commonFakeData(&r)
return r, err
}

func (d DummyService) CreateValidatorDashboard(userId uint64, name string, network uint64) (t.VDBPostReturnData, error) {
r := t.VDBPostReturnData{}
err := commonFakeData(&r)
Expand Down Expand Up @@ -87,7 +93,7 @@ func (d DummyService) RemoveValidatorDashboardGroup(dashboardId t.VDBIdPrimary,
return nil
}

func (d DummyService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []string) ([]t.VDBPostValidatorsData, error) {
func (d DummyService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) {
r := []t.VDBPostValidatorsData{}
err := commonFakeData(&r)
return r, err
Expand Down Expand Up @@ -117,7 +123,7 @@ func (d DummyService) GetValidatorDashboardValidatorsByValidators(dashboardId t.
return r, p, err
}

func (d DummyService) RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []string) error {
func (d DummyService) RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) error {
return nil
}

Expand Down
14 changes: 12 additions & 2 deletions backend/pkg/api/handlers/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,16 @@ func (h HandlerService) InternalPostValidatorDashboardValidators(w http.Response
vars := mux.Vars(r)
dashboardId := checkDashboardId(&err, vars["dashboard_id"], false)
groupId := checkGroupId(&err, req.GroupId)
validators := checkValidatorArray(&err, req.Validators)
validatorArr := checkValidatorArray(&err, req.Validators)
if err != nil {
returnBadRequest(w, err)
return
}
validators, err := h.dai.GetValidatorsFromStrings(validatorArr)
if err != nil {
returnInternalServerError(w, err)
return
}

var dashboardInfo types.DashboardInfo
switch dashboardId := dashboardId.(type) {
Expand Down Expand Up @@ -398,11 +403,16 @@ func (h HandlerService) InternalDeleteValidatorDashboardValidators(w http.Respon
vars := mux.Vars(r)
q := r.URL.Query()
dashboardId := checkDashboardId(&err, vars["dashboard_id"], false)
validators := checkValidatorList(&err, q.Get("validators"))
validatorArr := checkValidatorList(&err, q.Get("validators"))
if err != nil {
returnBadRequest(w, err)
return
}
validators, err := h.dai.GetValidatorsFromStrings(validatorArr)
if err != nil {
returnInternalServerError(w, err)
return
}

var dashboardInfo types.DashboardInfo
switch dashboardId := dashboardId.(type) {
Expand Down

0 comments on commit d16ae3e

Please sign in to comment.