Enable searching lists by their ids
continuous-integration/drone/pr Build was killed
Details
continuous-integration/drone/pr Build was killed
Details
Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
parent
4c7893cef3
commit
0c138a6ff5
|
@ -17,6 +17,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.vikunja.io/api/pkg/log"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.vikunja.io/api/pkg/files"
|
"code.vikunja.io/api/pkg/files"
|
||||||
|
@ -320,6 +323,24 @@ func getRawListsForUser(opts *listOptions) (lists []*List, resultCount int, tota
|
||||||
|
|
||||||
limit, start := getLimitFromPageIndex(opts.page, opts.perPage)
|
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
|
// 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
|
// Or in a team which has namespace read access
|
||||||
query := x.Select("l.*").
|
query := x.Select("l.*").
|
||||||
|
@ -340,7 +361,7 @@ func getRawListsForUser(opts *listOptions) (lists []*List, resultCount int, tota
|
||||||
builder.Eq{"l.owner_id": fullUser.ID},
|
builder.Eq{"l.owner_id": fullUser.ID},
|
||||||
)).
|
)).
|
||||||
GroupBy("l.id").
|
GroupBy("l.id").
|
||||||
Where("l.title LIKE ?", "%"+opts.search+"%").
|
Where(filterCond).
|
||||||
Where(isArchivedCond)
|
Where(isArchivedCond)
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
query = query.Limit(limit, start)
|
query = query.Limit(limit, start)
|
||||||
|
@ -368,7 +389,7 @@ func getRawListsForUser(opts *listOptions) (lists []*List, resultCount int, tota
|
||||||
builder.Eq{"l.owner_id": fullUser.ID},
|
builder.Eq{"l.owner_id": fullUser.ID},
|
||||||
)).
|
)).
|
||||||
GroupBy("l.id").
|
GroupBy("l.id").
|
||||||
Where("l.title LIKE ?", "%"+opts.search+"%").
|
Where(filterCond).
|
||||||
Where(isArchivedCond).
|
Where(isArchivedCond).
|
||||||
Count(&List{})
|
Count(&List{})
|
||||||
return lists, len(lists), totalItems, err
|
return lists, len(lists), totalItems, err
|
||||||
|
|
Loading…
Reference in New Issue