Add option to filter namespaces by slug
This commit is contained in:
@@ -86,6 +86,10 @@ func (r *namespace) Find(filter types.NamespaceFilter) (set types.NamespaceSet,
|
||||
query = query.Where("name like ? OR slug like ?", q, q)
|
||||
}
|
||||
|
||||
if f.Slug != "" {
|
||||
query = query.Where("LOWER(slug) = LOWER(?)", f.Slug)
|
||||
}
|
||||
|
||||
if f.Count, err = r.count(query); err != nil || f.Count == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ func (Namespace) New() *Namespace {
|
||||
func (ctrl Namespace) List(ctx context.Context, r *request.NamespaceList) (interface{}, error) {
|
||||
f := types.NamespaceFilter{
|
||||
Query: r.Query,
|
||||
Slug: r.Slug,
|
||||
PerPage: r.PerPage,
|
||||
Page: r.Page,
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ var _ = multipart.FileHeader{}
|
||||
// Namespace list request parameters
|
||||
type NamespaceList struct {
|
||||
Query string
|
||||
Slug string
|
||||
Page uint
|
||||
PerPage uint
|
||||
}
|
||||
@@ -48,6 +49,7 @@ func (r NamespaceList) Auditable() map[string]interface{} {
|
||||
var out = map[string]interface{}{}
|
||||
|
||||
out["query"] = r.Query
|
||||
out["slug"] = r.Slug
|
||||
out["page"] = r.Page
|
||||
out["perPage"] = r.PerPage
|
||||
|
||||
@@ -84,6 +86,9 @@ func (r *NamespaceList) Fill(req *http.Request) (err error) {
|
||||
if val, ok := get["query"]; ok {
|
||||
r.Query = val
|
||||
}
|
||||
if val, ok := get["slug"]; ok {
|
||||
r.Slug = val
|
||||
}
|
||||
if val, ok := get["page"]; ok {
|
||||
r.Page = parseUint(val)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ type (
|
||||
|
||||
NamespaceFilter struct {
|
||||
Query string `json:"query"`
|
||||
Slug string `json:"slug"`
|
||||
Page uint `json:"page"`
|
||||
PerPage uint `json:"perPage"`
|
||||
Sort string `json:"sort"`
|
||||
|
||||
Reference in New Issue
Block a user