Feat: list users

pull/247/head
HFO4 5 years ago
parent c7247f5b87
commit 38161250e8

@ -32,8 +32,8 @@ type User struct {
Status int
GroupID uint
Storage uint64
OpenID string `json:"-"`
TwoFactor string `json:"-"`
OpenID string
TwoFactor string
Avatar string
Options string `json:"-",gorm:"type:text"`
Authn string `gorm:"type:text"`

@ -271,3 +271,14 @@ func AdminGetGroup(c *gin.Context) {
c.JSON(200, ErrorResponse(err))
}
}
// AdminListUser 列出用户
func AdminListUser(c *gin.Context) {
var service admin.AdminListService
if err := c.ShouldBindJSON(&service); err == nil {
res := service.Users()
c.JSON(200, res)
} else {
c.JSON(200, ErrorResponse(err))
}
}

@ -365,6 +365,12 @@ func InitMasterRouter() *gin.Engine {
group.DELETE(":id", controllers.AdminDeleteGroup)
}
user := admin.Group("user")
{
// 列出用户
user.POST("list", controllers.AdminListUser)
}
}
// 用户

@ -0,0 +1,34 @@
package admin
import (
model "github.com/HFO4/cloudreve/models"
"github.com/HFO4/cloudreve/pkg/serializer"
)
// Users 列出用户
func (service *AdminListService) Users() serializer.Response {
var res []model.User
total := 0
tx := model.DB.Model(&model.User{})
if service.OrderBy != "" {
tx = tx.Order(service.OrderBy)
}
for k, v := range service.Conditions {
tx = tx.Where(k+" = ?", v)
}
// 计算总数用于分页
tx.Count(&total)
// 查询记录
tx.Set("gorm:auto_preload", true).Limit(service.PageSize).Offset((service.Page - 1) * service.PageSize).Find(&res)
// 补齐缺失用户组
return serializer.Response{Data: map[string]interface{}{
"total": total,
"items": res,
}}
}
Loading…
Cancel
Save