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

Commit

Permalink
Merge pull request #314 from threefoldtech/development_certfication_f…
Browse files Browse the repository at this point in the history
…ilter

add certification type filter to nodes list
  • Loading branch information
AhmedHanafy725 committed Apr 2, 2023
2 parents 7591ed6 + 7641060 commit c00fa5a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 27 deletions.
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

0 comments on commit c00fa5a

Please sign in to comment.