You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.3 KiB
102 lines
2.3 KiB
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"laic-backend/common"
|
|
"laic-backend/service"
|
|
"laic-backend/vo"
|
|
)
|
|
|
|
// GetUserPage 用户分页列表(admin)
|
|
func GetUserPage(c *gin.Context) {
|
|
var req vo.UserPageReq
|
|
_ = c.ShouldBindQuery(&req)
|
|
if req.PageNum <= 0 {
|
|
req.PageNum = 1
|
|
}
|
|
if req.PageSize <= 0 {
|
|
req.PageSize = 10
|
|
}
|
|
page, busiErr := service.DefaultSystemService.GetUserPage(&req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, page)
|
|
}
|
|
|
|
// CreateUser 创建用户(admin)
|
|
func CreateUser(c *gin.Context) {
|
|
var req vo.UserCreateReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
user, busiErr := service.DefaultSystemService.CreateUser(&req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, user)
|
|
}
|
|
|
|
// UpdateUser 编辑用户(admin)
|
|
func UpdateUser(c *gin.Context) {
|
|
id, busiErr := parseID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
var req vo.UserUpdateReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
user, busiErr := service.DefaultSystemService.UpdateUser(id, &req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, user)
|
|
}
|
|
|
|
// DeleteUser 删除用户(admin)
|
|
func DeleteUser(c *gin.Context) {
|
|
id, busiErr := parseID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
if busiErr := service.DefaultSystemService.DeleteUser(id); busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OK(c)
|
|
}
|
|
|
|
// GetRoles 角色列表(admin)
|
|
func GetRoles(c *gin.Context) {
|
|
common.OKWithData(c, service.DefaultSystemService.GetRoles())
|
|
}
|
|
|
|
// GetOperationLogPage 操作日志分页(admin 全量,user 仅本人)
|
|
func GetOperationLogPage(c *gin.Context) {
|
|
var req vo.OperationLogPageReq
|
|
_ = c.ShouldBindQuery(&req)
|
|
if req.PageNum <= 0 {
|
|
req.PageNum = 1
|
|
}
|
|
if req.PageSize <= 0 {
|
|
req.PageSize = 10
|
|
}
|
|
if !common.IsAdmin(c) {
|
|
req.UserID = common.GetUserId(c)
|
|
}
|
|
page, busiErr := service.DefaultOperationLogService.GetPage(&req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, page)
|
|
}
|
|
|