Skip to content

Commit 2ee2bd0

Browse files
committed
RHINENG-25944: add search for the tags list endpoint
Allow `/tags` to filter returned tags by matching the search term against tag namespace, key, and value. With this the `/tags` endpoint could be used in the frontend for tag filtering.
1 parent be93714 commit 2ee2bd0

3 files changed

Lines changed: 57 additions & 6 deletions

File tree

docs/v3/openapi.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5656,6 +5656,14 @@
56565656
"type": "integer"
56575657
}
56585658
},
5659+
{
5660+
"name": "search",
5661+
"in": "query",
5662+
"description": "Find matching text",
5663+
"schema": {
5664+
"type": "string"
5665+
}
5666+
},
56595667
{
56605668
"name": "offset",
56615669
"in": "query",

manager/controllers/systemtags.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package controllers
22

33
import (
4-
"app/base/database"
5-
"app/base/utils"
64
"errors"
75
"net/http"
86

7+
"app/base/database"
8+
"app/base/utils"
9+
910
"app/manager/middlewares"
1011

1112
"github.com/gin-gonic/gin"
@@ -48,16 +49,22 @@ var SystemTagsOpts = ListOpts{
4849
},
4950
StableSort: "tag",
5051
DefaultSort: "tag",
52+
SearchFields: []string{
53+
"sq.tag->>'namespace'",
54+
"sq.tag->>'key'",
55+
"sq.tag->>'value'",
56+
},
5157
}
5258

5359
// @Summary Show me systems tags applicable to this application
5460
// @Description Show me systems tags applicable to this application
5561
// @ID listSystemTags
5662
// @Security RhIdentity
5763
// @Produce json
58-
// @Param sort query string false "Sort field" Enums(tag, count)
59-
// @Param limit query int fals "Limit for paging"
60-
// @Param offset query int false "Offset for paging"
64+
// @Param sort query string false "Sort field" Enums(tag, count)
65+
// @Param limit query int false "Limit for paging"
66+
// @Param search query string false "Find matching text"
67+
// @Param offset query int false "Offset for paging"
6168
// @Success 200 {object} SystemTagsResponse
6269
// @Failure 400 {object} utils.ErrorResponse
6370
// @Failure 500 {object} utils.ErrorResponse

manager/controllers/systemtags_test.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package controllers
22

33
import (
4-
"app/base/core"
54
"net/http"
65
"testing"
76

7+
"app/base/core"
8+
89
"github.com/stretchr/testify/assert"
910
)
1011

@@ -76,3 +77,38 @@ func TestSystemTagsListBadRequestOnIdtSort(t *testing.T) {
7677
w := CreateRequestRouterWithAccount("GET", "/", "", "?sort=id", nil, "", SystemTagListHandler, 1)
7778
assert.Equal(t, 400, w.Code)
7879
}
80+
81+
func TestSystemTagsListSearch(t *testing.T) {
82+
core.SetupTest(t)
83+
84+
w := CreateRequestRouterWithAccount("GET", "/", "", "?search=k3", nil, "", SystemTagListHandler, 1)
85+
86+
var output SystemTagsResponse
87+
CheckResponse(t, w, http.StatusOK, &output)
88+
89+
assert.Equal(t, 2, len(output.Data))
90+
assert.Equal(t, 2, output.Meta.TotalItems)
91+
assert.Equal(t, "k3", output.Meta.Search)
92+
93+
assert.Equal(t, 1, output.Data[0].Count)
94+
assert.Equal(t, "k3", output.Data[0].Tag.Key)
95+
assert.Equal(t, "ns1", output.Data[0].Tag.Namespace)
96+
assert.Equal(t, "val3", output.Data[0].Tag.Value)
97+
98+
assert.Equal(t, 3, output.Data[1].Count)
99+
assert.Equal(t, "k3", output.Data[1].Tag.Key)
100+
assert.Equal(t, "ns1", output.Data[1].Tag.Namespace)
101+
assert.Equal(t, "val4", output.Data[1].Tag.Value)
102+
}
103+
104+
func TestSystemTagsListSearchUnknown(t *testing.T) {
105+
core.SetupTest(t)
106+
107+
w := CreateRequestRouterWithAccount("GET", "/", "", "?search=unknown", nil, "", SystemTagListHandler, 1)
108+
109+
var output SystemTagsResponse
110+
CheckResponse(t, w, http.StatusOK, &output)
111+
112+
assert.Equal(t, 0, len(output.Data))
113+
assert.Equal(t, "unknown", output.Meta.Search)
114+
}

0 commit comments

Comments
 (0)