refactor🎨: 缩减函数名称

This commit is contained in:
zhangwenjian
2021-06-07 16:39:26 +08:00
parent 6e01c13e1c
commit 190dcfedc0
12 changed files with 164 additions and 353 deletions
+2 -38
View File
@@ -1,14 +1,9 @@
package dto
import (
"encoding/json"
"go-admin/app/admin/models"
common "go-admin/common/models"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/common/dto"
)
@@ -39,16 +34,6 @@ func (m *SysRoleSearch) GetNeedSearch() interface{} {
return *m
}
// Bind 映射上下文中的结构体数据
func (m *SysRoleSearch) Bind(ctx *gin.Context) error {
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(m)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
}
return err
}
// SysConfigControl 增、改使用的结构体
type SysRoleControl struct {
RoleId int `uri:"id" comment:"角色编码"` // 角色编码
@@ -73,28 +58,7 @@ func (s *SysRoleControl) SetUpdateBy(id int) {
s.UpdateBy = id
}
// Bind 映射上下文中的结构体数据
func (s *SysRoleControl) Bind(ctx *gin.Context) error {
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindBodyWith(s, binding.JSON)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
}
err = ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
return err
}
var jsonStr []byte
jsonStr, err = json.Marshal(s)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
}
ctx.Set("body", string(jsonStr))
return err
}
// Generate 结构体数据转化 从 SysConfigControl 至 system.SysConfig 对应的模型
// Generate 结构体数据转化
func (s *SysRoleControl) Generate(model *models.SysRole) {
if s.RoleId != 0 {
model.RoleId = s.RoleId
@@ -107,7 +71,7 @@ func (s *SysRoleControl) Generate(model *models.SysRole) {
model.Remark = s.Remark
model.Admin = s.Admin
model.DataScope = s.DataScope
model.SysMenu = s.SysMenu
model.SysMenu = &s.SysMenu
}
-92
View File
@@ -1,92 +0,0 @@
package dto
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models"
)
// SysConfigControl 增、改使用的结构体
type SysSettingControl struct {
SettingsId int `json:"settings_id" binding:"required"` // 头像
Name string `json:"name" binding:"required"` // 名称
Logo string `json:"logo" binding:"required"` // 头像
}
// Bind 映射上下文中的结构体数据
func (s *SysSettingControl) Bind(ctx *gin.Context) error {
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBind(s)
if err != nil {
log.Errorf("ShouldBind error: %s", err.Error())
return err
}
err = ctx.ShouldBindUri(s)
if err != nil {
log.Errorf("ShouldBindUri error: %s", err.Error())
return err
}
var jsonStr []byte
jsonStr, err = json.Marshal(s)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
}
ctx.Set("body", string(jsonStr))
return err
}
// Generate 结构体数据转化 从 SysConfigControl 至 system.SysConfig 对应的模型
func (s *SysSettingControl) Generate() (*models.SysSetting, error) {
return &models.SysSetting{
SettingsId: s.SettingsId,
Name: s.Name,
Logo: s.Logo,
}, nil
}
// GetId 获取数据对应的ID
func (s *SysSettingControl) GetId() interface{} {
return s.SettingsId
}
// SysConfigById 获取单个或者删除的结构体
type SysSettingById struct {
Id int `uri:"id"`
Ids []int `json:"ids"`
}
func (s *SysSettingById) Generate() *SysSettingById {
cp := *s
return &cp
}
func (s *SysSettingById) GetId() interface{} {
if len(s.Ids) > 0 {
s.Ids = append(s.Ids, s.Id)
return s.Ids
}
return s.Id
}
func (s *SysSettingById) Bind(ctx *gin.Context) error {
log := api.GetRequestLogger(ctx)
err := ctx.ShouldBindUri(s)
if err != nil {
log.Debugf("ShouldBindUri error: %s", err.Error())
return err
}
err = ctx.ShouldBind(s)
if err != nil {
log.Debugf("ShouldBind error: %s", err.Error())
}
return err
}
func (s *SysSettingById) GenerateM() (*models.SysSetting, error) {
return &models.SysSetting{}, nil
}
+4 -1
View File
@@ -16,9 +16,9 @@ type SysUserSearch struct {
RoleId string `form:"roleId" search:"type:exact;column:role_id;table:sys_user" comment:"角色ID"`
Sex string `form:"sex" search:"type:exact;column:sex;table:sys_user" comment:"性别"`
Email string `form:"email" search:"type:contains;column:email;table:sys_user" comment:"邮箱"`
DeptId string `form:"deptId" search:"type:exact;column:dept_id;table:sys_user" comment:"部门"`
PostId string `form:"postId" search:"type:exact;column:post_id;table:sys_user" comment:"岗位"`
Status string `form:"status" search:"type:exact;column:status;table:sys_user" comment:"状态"`
DeptJoin `search:"type:left;on:dept_id:dept_id;table:sys_user;join:sys_dept"`
SysUserOrder
}
@@ -29,6 +29,9 @@ type SysUserOrder struct {
CreatedAtOrder string `search:"type:order;column:created_at;table:sys_user" form:"createdAtOrder"`
}
type DeptJoin struct {
DeptId string `search:"type:contains;column:dept_path;table:sys_dept" form:"deptId"`
}
func (m *SysUserSearch) GetNeedSearch() interface{} {
return *m