mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-01-06 06:35:47 +08:00
refactor: 使用泛型重构参数绑定等
This commit is contained in:
@@ -108,7 +108,7 @@ func (a *Account) GetPermissions(rc *req.Ctx) {
|
||||
func (a *Account) ChangePassword(rc *req.Ctx) {
|
||||
ctx := rc.MetaCtx
|
||||
|
||||
form := req.BindJsonAndValid(rc, new(form.AccountChangePasswordForm))
|
||||
form := req.BindJsonAndValid[*form.AccountChangePasswordForm](rc)
|
||||
|
||||
originOldPwd, err := utils.DefaultRsaDecrypt(form.OldPassword, true)
|
||||
biz.ErrIsNilAppendErr(err, "Wrong to decrypt old password: %s")
|
||||
@@ -145,9 +145,10 @@ func (a *Account) AccountInfo(rc *req.Ctx) {
|
||||
|
||||
// 更新个人账号信息
|
||||
func (a *Account) UpdateAccount(rc *req.Ctx) {
|
||||
updateAccount := req.BindJsonAndCopyTo[*entity.Account](rc, new(form.AccountUpdateForm), new(entity.Account))
|
||||
form, updateAccount := req.BindJsonAndCopyTo[*form.AccountUpdateForm, *entity.Account](rc)
|
||||
// 账号id为登录者账号
|
||||
updateAccount.Id = rc.GetLoginAccount().Id
|
||||
rc.ReqParam = form
|
||||
|
||||
ctx := rc.MetaCtx
|
||||
if updateAccount.Password != "" {
|
||||
@@ -210,8 +211,7 @@ func (a *Account) AccountDetail(rc *req.Ctx) {
|
||||
|
||||
// @router /accounts
|
||||
func (a *Account) SaveAccount(rc *req.Ctx) {
|
||||
form := &form.AccountCreateForm{}
|
||||
account := req.BindJsonAndCopyTo(rc, form, new(entity.Account))
|
||||
form, account := req.BindJsonAndCopyTo[*form.AccountCreateForm, *entity.Account](rc)
|
||||
|
||||
form.Password = "*****"
|
||||
rc.ReqParam = form
|
||||
@@ -307,7 +307,7 @@ func (a *Account) AccountResources(rc *req.Ctx) {
|
||||
|
||||
// 关联账号角色
|
||||
func (a *Account) RelateRole(rc *req.Ctx) {
|
||||
form := req.BindJsonAndValid(rc, new(form.AccountRoleForm))
|
||||
form := req.BindJsonAndValid[*form.AccountRoleForm](rc)
|
||||
rc.ReqParam = form
|
||||
biz.ErrIsNil(a.roleApp.RelateAccountRole(rc.MetaCtx, form.Id, form.RoleId, consts.AccountRoleRelateType(form.RelateType)))
|
||||
}
|
||||
|
||||
@@ -55,8 +55,7 @@ func (c *Config) GetConfigValueByKey(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (c *Config) SaveConfig(rc *req.Ctx) {
|
||||
form := &form.ConfigForm{}
|
||||
config := req.BindJsonAndCopyTo(rc, form, new(entity.Config))
|
||||
form, config := req.BindJsonAndCopyTo[*form.ConfigForm, *entity.Config](rc)
|
||||
rc.ReqParam = form
|
||||
biz.ErrIsNil(c.configApp.Save(rc.MetaCtx, config))
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@ func (r *Resource) GetById(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (r *Resource) SaveResource(rc *req.Ctx) {
|
||||
form := new(form.ResourceForm)
|
||||
entity := req.BindJsonAndCopyTo(rc, form, new(entity.Resource))
|
||||
form, entity := req.BindJsonAndCopyTo[*form.ResourceForm, *entity.Resource](rc)
|
||||
|
||||
rc.ReqParam = form
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ func (r *Role) ReqConfs() *req.Confs {
|
||||
}
|
||||
|
||||
func (r *Role) Roles(rc *req.Ctx) {
|
||||
cond := req.BindQuery(rc, new(entity.RoleQuery))
|
||||
cond := req.BindQuery[*entity.RoleQuery](rc)
|
||||
|
||||
notIdsStr := rc.Query("notIds")
|
||||
if notIdsStr != "" {
|
||||
@@ -61,8 +61,7 @@ func (r *Role) Roles(rc *req.Ctx) {
|
||||
|
||||
// 保存角色信息
|
||||
func (r *Role) SaveRole(rc *req.Ctx) {
|
||||
form := &form.RoleForm{}
|
||||
role := req.BindJsonAndCopyTo(rc, form, new(entity.Role))
|
||||
form, role := req.BindJsonAndCopyTo[*form.RoleForm, *entity.Role](rc)
|
||||
rc.ReqParam = form
|
||||
|
||||
r.roleApp.SaveRole(rc.MetaCtx, role)
|
||||
@@ -93,8 +92,7 @@ func (r *Role) RoleResource(rc *req.Ctx) {
|
||||
|
||||
// 保存角色资源
|
||||
func (r *Role) SaveResource(rc *req.Ctx) {
|
||||
var form form.RoleResourceForm
|
||||
req.BindJsonAndValid(rc, &form)
|
||||
form := req.BindJsonAndValid[*form.RoleResourceForm](rc)
|
||||
rc.ReqParam = form
|
||||
|
||||
// 将,拼接的字符串进行切割并转换
|
||||
@@ -107,7 +105,7 @@ func (r *Role) SaveResource(rc *req.Ctx) {
|
||||
|
||||
// 查看角色关联的用户
|
||||
func (r *Role) RoleAccount(rc *req.Ctx) {
|
||||
cond := req.BindQuery(rc, new(entity.RoleAccountQuery))
|
||||
cond := req.BindQuery[*entity.RoleAccountQuery](rc)
|
||||
cond.RoleId = uint64(rc.PathParamInt("id"))
|
||||
res, err := r.roleApp.GetRoleAccountPage(cond)
|
||||
biz.ErrIsNil(err)
|
||||
|
||||
@@ -21,7 +21,7 @@ func (s *Syslog) ReqConfs() *req.Confs {
|
||||
}
|
||||
|
||||
func (r *Syslog) Syslogs(rc *req.Ctx) {
|
||||
queryCond := req.BindQuery(rc, new(entity.SysLogQuery))
|
||||
queryCond := req.BindQuery[*entity.SysLogQuery](rc)
|
||||
res, err := r.syslogApp.GetPageList(queryCond, "create_time DESC")
|
||||
biz.ErrIsNil(err)
|
||||
rc.ResData = res
|
||||
|
||||
Reference in New Issue
Block a user