3
0

Support searching modules by name

This commit is contained in:
Denis Arh 2019-08-17 08:42:21 +02:00
parent a0bbe01c24
commit 7fd9c7fdfb
7 changed files with 25 additions and 0 deletions

View File

@ -444,6 +444,12 @@
"required": false,
"title": "Search query"
},
{
"type": "string",
"name": "name",
"required": false,
"title": "Search by name"
},
{
"name": "page",
"type": "uint",

View File

@ -38,6 +38,12 @@
"title": "Search query",
"type": "string"
},
{
"name": "name",
"required": false,
"title": "Search by name",
"type": "string"
},
{
"name": "page",
"required": false,

View File

@ -97,6 +97,11 @@ func (r module) Find(filter types.ModuleFilter) (set types.ModuleSet, f types.Mo
query = query.Where("name like ?", q)
}
if f.Name != "" {
query = query.Where("LOWER(name) = ?", strings.ToLower(f.Name))
}
if f.Count, err = r.count(query); err != nil || f.Count == 0 {
return
}

View File

@ -72,6 +72,7 @@ func (ctrl *Module) List(ctx context.Context, r *request.ModuleList) (interface{
f := types.ModuleFilter{
NamespaceID: r.NamespaceID,
Query: r.Query,
Name: r.Name,
PerPage: r.PerPage,
Page: r.Page,
}

View File

@ -37,6 +37,7 @@ var _ = multipart.FileHeader{}
// Module list request parameters
type ModuleList struct {
Query string
Name string
Page uint
PerPage uint
NamespaceID uint64 `json:",string"`
@ -50,6 +51,7 @@ func (r ModuleList) Auditable() map[string]interface{} {
var out = map[string]interface{}{}
out["query"] = r.Query
out["name"] = r.Name
out["page"] = r.Page
out["perPage"] = r.PerPage
out["namespaceID"] = r.NamespaceID
@ -87,6 +89,9 @@ func (r *ModuleList) Fill(req *http.Request) (err error) {
if val, ok := get["query"]; ok {
r.Query = val
}
if val, ok := get["name"]; ok {
r.Name = val
}
if val, ok := get["page"]; ok {
r.Page = parseUint(val)
}

View File

@ -24,6 +24,7 @@ type (
ModuleFilter struct {
NamespaceID uint64 `json:"namespaceID,string"`
Query string `json:"query"`
Name string `json:"name"`
Page uint `json:"page"`
PerPage uint `json:"perPage"`
// Sort string `json:"sort"`

View File

@ -505,6 +505,7 @@ Compose module definitions
| Parameter | Type | Method | Description | Default | Required? |
| --------- | ---- | ------ | ----------- | ------- | --------- |
| query | string | GET | Search query | N/A | NO |
| name | string | GET | Search by name | N/A | NO |
| page | uint | GET | Page number (0 based) | N/A | NO |
| perPage | uint | GET | Returned items per page (default 50) | N/A | NO |
| namespaceID | uint64 | PATH | Namespace ID | N/A | YES |