Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

add certification type filter to nodes list #314

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/explorer/db/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ func (d *PostgresDatabase) GetNodes(filter types.NodeFilter, limit types.Limit)
if filter.Rented != nil {
q = q.Where(`? = (COALESCE(rent_contract.contract_id, 0) != 0)`, *filter.Rented)
}
if filter.CertificationType != nil {
q = q.Where("node.certification ILIKE ?", *filter.CertificationType)
}

var count int64
if limit.Randomize || limit.RetCount {
Expand Down
1 change: 1 addition & 0 deletions internal/explorer/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (a *App) handleNodeRequestsQueryParams(r *http.Request) (types.NodeFilter,
"country_contains": &filter.CountryContains,
"farm_name": &filter.FarmName,
"farm_name_contains": &filter.FarmNameContains,
"certification_type": &filter.CertificationType,
}
bools := map[string]**bool{
"ipv4": &filter.IPv4,
Expand Down
4 changes: 3 additions & 1 deletion internal/explorer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
// @Param twin_id query int false "twin id associated with the farm"
// @Param name query string false "farm name"
// @Param name_contains query string false "farm name contains"
// @Param certification_type query string false "certificate type DIY or Certified"
// @Param certification_type query string false "certificate type Diy or Certified"
// @Param dedicated query bool false "farm is dedicated"
// @Param stellar_address query string false "farm stellar_address"
// @Success 200 {object} []types.Farm
Expand Down Expand Up @@ -128,6 +128,7 @@ func (a *App) getStats(r *http.Request) (interface{}, mw.Response) {
// @Param rented_by query int false "rented by twin id"
// @Param available_for query int false "available for twin id"
// @Param farm_ids query string false "List of farms separated by comma to fetch nodes from (e.g. '1,2,3')"
// @Param certification_type query string false "certificate type Diy or Certified"
// @Success 200 {object} []types.Node
// @Failure 400 {object} string
// @Failure 500 {object} string
Expand Down Expand Up @@ -162,6 +163,7 @@ func (a *App) getNodes(r *http.Request) (interface{}, mw.Response) {
// @Param rented_by query int false "rented by twin id"
// @Param available_for query int false "available for twin id"
// @Param farm_ids query string false "List of farms separated by comma to fetch nodes from (e.g. '1,2,3')"
// @Param certification_type query string false "certificate type Diy or Certified"
// @Success 200 {object} []types.Node
// @Failure 400 {object} string
// @Failure 500 {object} string
Expand Down
3 changes: 3 additions & 0 deletions pkg/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func nodeParams(filter types.NodeFilter, limit types.Limit) string {
if limit.Randomize {
fmt.Fprintf(&builder, "randomize=true&")
}
if filter.CertificationType != nil && *filter.CertificationType != "" {
fmt.Fprintf(&builder, "certification_type=%s&", url.QueryEscape(*filter.CertificationType))
}

res := builder.String()
// pop the extra ? or &
Expand Down
53 changes: 27 additions & 26 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,33 @@ type Limit struct {

// NodeFilter node filters
type NodeFilter struct {
Status *string
FreeMRU *uint64
FreeHRU *uint64
FreeSRU *uint64
TotalMRU *uint64
TotalHRU *uint64
TotalSRU *uint64
TotalCRU *uint64
Country *string
CountryContains *string
City *string
CityContains *string
FarmName *string
FarmNameContains *string
FarmIDs []uint64
FreeIPs *uint64
IPv4 *bool
IPv6 *bool
Domain *bool
Dedicated *bool
Rentable *bool
Rented *bool
RentedBy *uint64
AvailableFor *uint64
NodeID *uint64
TwinID *uint64
Status *string
FreeMRU *uint64
FreeHRU *uint64
FreeSRU *uint64
TotalMRU *uint64
TotalHRU *uint64
TotalSRU *uint64
TotalCRU *uint64
Country *string
CountryContains *string
City *string
CityContains *string
FarmName *string
FarmNameContains *string
FarmIDs []uint64
FreeIPs *uint64
IPv4 *bool
IPv6 *bool
Domain *bool
Dedicated *bool
Rentable *bool
Rented *bool
RentedBy *uint64
AvailableFor *uint64
NodeID *uint64
TwinID *uint64
CertificationType *string
}

// FarmFilter farm filters
Expand Down
15 changes: 15 additions & 0 deletions tests/queries/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ func TestNode(t *testing.T) {
assert.NoError(t, err)
nodePaginationCheck(t, localClient, proxyClient)
})

t.Run("nodes test certification_type filter", func(t *testing.T) {
certType := "Diy"
nodes, _, err := proxyClient.Nodes(proxytypes.NodeFilter{CertificationType: &certType}, proxytypes.Limit{})
assert.NoError(t, err)

for _, node := range nodes {
assert.Equal(t, node.CertificationType, certType, "certification_type filter did not work")
}

notExistCertType := "noCert"
nodes, _, err = proxyClient.Nodes(proxytypes.NodeFilter{CertificationType: &notExistCertType}, proxytypes.Limit{})
assert.NoError(t, err)
assert.Empty(t, nodes)
})
}

func singleNodeCheck(t *testing.T, localClient proxyclient.Client, proxyClient proxyclient.Client) {
Expand Down