Add sorting functionality to user search endpoint
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
ad9c5acba9
commit
dbbd359984
3 changed files with 105 additions and 1 deletions
|
@ -416,6 +416,11 @@ func SearchUsers(ctx *context.APIContext) {
|
|||
// in: query
|
||||
// description: user's login name to search for
|
||||
// type: string
|
||||
// - name: sort
|
||||
// in: query
|
||||
// description: sort order of results
|
||||
// type: string
|
||||
// enum: [oldest, newest, alphabetically, reversealphabetically, recentupdate, leastupdate]
|
||||
// - name: page
|
||||
// in: query
|
||||
// description: page number of results to return (1-based)
|
||||
|
@ -431,6 +436,27 @@ func SearchUsers(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
sort := ctx.FormString("sort")
|
||||
var orderBy db.SearchOrderBy
|
||||
|
||||
switch sort {
|
||||
case "oldest":
|
||||
orderBy = db.SearchOrderByOldest
|
||||
case "newest":
|
||||
orderBy = db.SearchOrderByNewest
|
||||
case "alphabetically":
|
||||
orderBy = db.SearchOrderByAlphabetically
|
||||
case "reversealphabetically":
|
||||
orderBy = db.SearchOrderByAlphabeticallyReverse
|
||||
case "recentupdate":
|
||||
orderBy = db.SearchOrderByRecentUpdated
|
||||
case "leastupdate":
|
||||
orderBy = db.SearchOrderByLeastUpdated
|
||||
default:
|
||||
orderBy = db.SearchOrderByAlphabetically
|
||||
}
|
||||
|
||||
intSource, err := strconv.ParseInt(ctx.FormString("source_id"), 10, 64)
|
||||
var sourceID optional.Option[int64]
|
||||
if ctx.FormString("source_id") == "" || err != nil {
|
||||
|
@ -444,7 +470,7 @@ func SearchUsers(ctx *context.APIContext) {
|
|||
Type: user_model.UserTypeIndividual,
|
||||
LoginName: ctx.FormTrim("login_name"),
|
||||
SourceID: sourceID,
|
||||
OrderBy: db.SearchOrderByAlphabetically,
|
||||
OrderBy: orderBy,
|
||||
ListOptions: listOptions,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue