1
0

Add task filter for lists and namespaces (#748)

Add more tests for getting namespaces

Fix namespaces not found

Fix namespaces not found

Make like the default

Update docs & fix docs

Enable searching namespaces by their ids

Enable searching lists by their ids

Enable searching labels by their ids

Enable searching by user ids

Update docs

Add namespace filter

Add task filter for lists

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/748
Co-Authored-By: konrad <konrad@kola-entertainments.de>
Co-Committed-By: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad
2020-12-21 23:13:15 +00:00
parent 111efd5fae
commit 2d4e2e452c
12 changed files with 288 additions and 51 deletions

View File

@ -17,8 +17,12 @@
package models
import (
"strconv"
"strings"
"time"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/user"
@ -320,6 +324,24 @@ func getRawListsForUser(opts *listOptions) (lists []*List, resultCount int, tota
limit, start := getLimitFromPageIndex(opts.page, opts.perPage)
var filterCond builder.Cond
vals := strings.Split(opts.search, ",")
ids := []int64{}
for _, val := range vals {
v, err := strconv.ParseInt(val, 10, 64)
if err != nil {
log.Debugf("List search string part '%s' is not a number: %s", val, err)
continue
}
ids = append(ids, v)
}
if len(ids) > 0 {
filterCond = builder.In("l.id", ids)
} else {
filterCond = &builder.Like{"l.title", "%" + opts.search + "%"}
}
// Gets all Lists where the user is either owner or in a team which has access to the list
// Or in a team which has namespace read access
query := x.Select("l.*").
@ -340,7 +362,7 @@ func getRawListsForUser(opts *listOptions) (lists []*List, resultCount int, tota
builder.Eq{"l.owner_id": fullUser.ID},
)).
GroupBy("l.id").
Where("l.title LIKE ?", "%"+opts.search+"%").
Where(filterCond).
Where(isArchivedCond)
if limit > 0 {
query = query.Limit(limit, start)
@ -368,7 +390,7 @@ func getRawListsForUser(opts *listOptions) (lists []*List, resultCount int, tota
builder.Eq{"l.owner_id": fullUser.ID},
)).
GroupBy("l.id").
Where("l.title LIKE ?", "%"+opts.search+"%").
Where(filterCond).
Where(isArchivedCond).
Count(&List{})
return lists, len(lists), totalItems, err