Add GetSortedUsers() and GetUserCount() APIs.

This commit is contained in:
Gucheng Wang
2021-11-19 10:43:14 +08:00
parent 1394dce306
commit 0b3742b0b1
3 changed files with 88 additions and 1 deletions

View File

@ -73,8 +73,17 @@ func (c *ApiController) GetUsers() {
// @router /get-user [get]
func (c *ApiController) GetUser() {
id := c.Input().Get("id")
owner := c.Input().Get("owner")
email := c.Input().Get("email")
c.Data["json"] = object.GetMaskedUser(object.GetUser(id))
var user *object.User
if email == "" {
user = object.GetUser(id)
} else {
user = object.GetUserByEmail(owner, email)
}
c.Data["json"] = object.GetMaskedUser(user)
c.ServeJSON()
}
@ -265,3 +274,42 @@ func (c *ApiController) CheckUserPassword() {
c.ResponseError(msg)
}
}
// GetSortedUsers
// @Title GetSortedUsers
// @Description
// @Param owner query string true "The owner of users"
// @Param sorter query string true "The DB column name to sort by, e.g., created_time"
// @Param limit query string true "The count of users to return, e.g., 25"
// @Success 200 {array} object.User The Response object
// @router /get-sorted-users [get]
func (c *ApiController) GetSortedUsers() {
owner := c.Input().Get("owner")
sorter := c.Input().Get("sorter")
limit := util.ParseInt(c.Input().Get("limit"))
c.Data["json"] = object.GetMaskedUsers(object.GetSortedUsers(owner, sorter, limit))
c.ServeJSON()
}
// GetUserCount
// @Title GetUserCount
// @Description
// @Param owner query string true "The owner of users"
// @Param isOnline query string true "The filter for query, 1 for online, 0 for offline, empty string for all users"
// @Success 200 {int} int The count of filtered users for an organization
// @router /get-user-count [get]
func (c *ApiController) GetUserCount() {
owner := c.Input().Get("owner")
isOnline := c.Input().Get("isOnline")
count := 0
if isOnline == "" {
count = object.GetUserCount(owner)
} else {
count = object.GetOnlineUserCount(owner, util.ParseInt(isOnline))
}
c.Data["json"] = count
c.ServeJSON()
}