refactor: 后端路由定义方式&请求参数绑定重构

This commit is contained in:
meilin.huang
2023-07-08 20:05:55 +08:00
parent 183a6e4905
commit 3269dfa5d6
59 changed files with 559 additions and 1020 deletions

View File

@@ -283,11 +283,7 @@ func (a *Account) AccountInfo(rc *req.Ctx) {
// 更新个人账号信息
func (a *Account) UpdateAccount(rc *req.Ctx) {
updateForm := &form.AccountUpdateForm{}
ginx.BindJsonAndValid(rc.GinCtx, updateForm)
updateAccount := new(entity.Account)
utils.Copy(updateAccount, updateForm)
updateAccount := ginx.BindJsonAndCopyTo[*entity.Account](rc.GinCtx, new(form.AccountUpdateForm), new(entity.Account))
// 账号id为登录者账号
updateAccount.Id = rc.LoginAccount.Id
@@ -310,11 +306,10 @@ func (a *Account) Accounts(rc *req.Ctx) {
// @router /accounts
func (a *Account) SaveAccount(rc *req.Ctx) {
form := &form.AccountCreateForm{}
ginx.BindJsonAndValid(rc.GinCtx, form)
rc.ReqParam = form
account := ginx.BindJsonAndCopyTo(rc.GinCtx, form, new(entity.Account))
account := &entity.Account{}
utils.Copy(account, form)
form.Password = "*****"
rc.ReqParam = form
account.SetBaseInfo(rc.LoginAccount)
if account.Id == 0 {

View File

@@ -7,7 +7,6 @@ import (
"mayfly-go/pkg/biz"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
)
type Config struct {
@@ -27,13 +26,9 @@ func (c *Config) GetConfigValueByKey(rc *req.Ctx) {
}
func (c *Config) SaveConfig(rc *req.Ctx) {
g := rc.GinCtx
form := &form.ConfigForm{}
ginx.BindJsonAndValid(g, form)
config := ginx.BindJsonAndCopyTo(rc.GinCtx, form, new(entity.Config))
rc.ReqParam = form
config := new(entity.Config)
utils.Copy(config, form)
config.SetBaseInfo(rc.LoginAccount)
c.ConfigApp.Save(config)
}

View File

@@ -9,7 +9,6 @@ import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/pkg/ginx"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils"
)
type Resource struct {
@@ -29,11 +28,10 @@ func (r *Resource) GetById(rc *req.Ctx) {
func (r *Resource) SaveResource(rc *req.Ctx) {
g := rc.GinCtx
form := new(form.ResourceForm)
ginx.BindJsonAndValid(g, form)
entity := ginx.BindJsonAndCopyTo(g, form, new(entity.Resource))
rc.ReqParam = form
entity := new(entity.Resource)
utils.Copy(entity, form)
// 将meta转为json字符串存储
bytes, _ := json.Marshal(form.Meta)
entity.Meta = string(bytes)

View File

@@ -27,13 +27,9 @@ func (r *Role) Roles(rc *req.Ctx) {
// 保存角色信息
func (r *Role) SaveRole(rc *req.Ctx) {
g := rc.GinCtx
form := &form.RoleForm{}
ginx.BindJsonAndValid(g, form)
role := ginx.BindJsonAndCopyTo(rc.GinCtx, form, new(entity.Role))
rc.ReqParam = form
role := new(entity.Role)
utils.Copy(role, form)
role.SetBaseInfo(rc.LoginAccount)
r.RoleApp.SaveRole(role)

View File

@@ -12,11 +12,6 @@ type Syslog struct {
}
func (r *Syslog) Syslogs(rc *req.Ctx) {
g := rc.GinCtx
condition := &entity.Syslog{
Type: int8(ginx.QueryInt(g, "type", 0)),
CreatorId: uint64(ginx.QueryInt(g, "creatorId", 0)),
Description: ginx.Query(g, "description", ""),
}
rc.ResData = r.SyslogApp.GetPageList(condition, ginx.GetPageParam(g), new([]entity.Syslog), "create_time DESC")
queryCond, page := ginx.BindQueryAndPage[*entity.SysLogQuery](rc.GinCtx, new(entity.SysLogQuery))
rc.ResData = r.SyslogApp.GetPageList(queryCond, page, new([]entity.SysLog), "create_time DESC")
}