users: adds search and pagination (#7753)

ref #7469. Follow up change that adds proper paging with 50 results
per page as well as a search box to search by name, login or email.
This commit is contained in:
Daniel Lee
2017-03-07 16:03:54 +01:00
committed by Torkel Ödegaard
parent 8e3f22d307
commit 9efb6e76e9
5 changed files with 73 additions and 6 deletions

View File

@ -363,8 +363,12 @@ func SearchUsers(query *m.SearchUsersQuery) error {
query.Result = m.SearchUserQueryResult{
Users: make([]*m.UserSearchHitDTO, 0),
}
queryWithWildcards := "%" + query.Query + "%"
sess := x.Table("user")
sess.Where("email LIKE ?", query.Query+"%")
if query.Query != "" {
sess.Where("email LIKE ? OR name LIKE ? OR login like ?", queryWithWildcards, queryWithWildcards, queryWithWildcards)
}
offset := query.Limit * (query.Page - 1)
sess.Limit(query.Limit, offset)
sess.Cols("id", "email", "name", "login", "is_admin")
@ -373,7 +377,12 @@ func SearchUsers(query *m.SearchUsersQuery) error {
}
user := m.User{}
count, err := x.Count(&user)
countSess := x.Table("user")
if query.Query != "" {
countSess.Where("email LIKE ? OR name LIKE ? OR login like ?", queryWithWildcards, queryWithWildcards, queryWithWildcards)
}
count, err := countSess.Count(&user)
query.Result.TotalCount = count
return err
}