Files
mayfly-go/server/internal/sys/router/account.go

65 lines
1.9 KiB
Go
Raw Normal View History

package router
import (
2023-07-03 21:42:04 +08:00
msgapp "mayfly-go/internal/msg/application"
"mayfly-go/internal/sys/api"
"mayfly-go/internal/sys/application"
2023-01-14 16:29:52 +08:00
"mayfly-go/pkg/req"
"github.com/gin-gonic/gin"
)
func InitAccountRouter(router *gin.RouterGroup) {
account := router.Group("sys/accounts")
2021-09-11 14:04:09 +08:00
a := &api.Account{
2022-09-09 18:26:08 +08:00
AccountApp: application.GetAccountApp(),
ResourceApp: application.GetResourceApp(),
RoleApp: application.GetRoleApp(),
2023-07-03 21:42:04 +08:00
MsgApp: msgapp.GetMsgApp(),
2022-09-09 18:26:08 +08:00
ConfigApp: application.GetConfigApp(),
}
addAccountPermission := req.NewPermission("account:add")
reqs := [...]*req.Conf{
2023-06-17 15:15:03 +08:00
// 获取个人账号的权限资源信息
req.NewGet("/permissions", a.GetPermissions),
req.NewPost("/change-pwd", a.ChangePassword).DontNeedToken().Log(req.NewLogSave("用户修改密码")),
2021-09-11 14:04:09 +08:00
// 获取个人账号信息
req.NewGet("/self", a.AccountInfo),
2021-09-11 14:04:09 +08:00
// 更新个人账号信息
req.NewPut("/self", a.UpdateAccount),
2021-09-11 14:04:09 +08:00
/** 后台管理接口 **/
// 获取所有用户列表
req.NewGet("", a.Accounts),
req.NewPost("", a.SaveAccount).Log(req.NewLogSave("保存账号信息")).RequiredPermission(addAccountPermission),
req.NewPut("change-status/:id/:status", a.ChangeStatus).Log(req.NewLogSave("修改账号状态")).RequiredPermission(addAccountPermission),
req.NewPut(":id/reset-otp", a.ResetOtpSecret).Log(req.NewLogSave("重置OTP密钥")).RequiredPermission(addAccountPermission),
req.NewDelete(":id", a.DeleteAccount).Log(req.NewLogSave("删除账号")).RequiredPermissionCode("account:del"),
// 获取所有用户角色id列表
req.NewGet(":id/roleIds", a.AccountRoleIds),
// 保存用户角色
req.NewPost("/roles", a.SaveRoles).Log(req.NewLogSave("保存用户角色")).RequiredPermissionCode("account:saveRoles"),
// 获取用户角色
req.NewGet(":id/roles", a.AccountRoles),
// 获取用户资源列表
req.NewGet(":id/resources", a.AccountResources),
}
req.BatchSetGroup(account, reqs[:])
}