refactor🎨: 简化数据绑定

This commit is contained in:
zhangwenjian committed 2021-06-07 16:39:59 +08:00
1 parent 190dcfedc0
commit 3be02f1364
6 files changed
+3 -154

No files matched your search

-37
View File
@@ -2,11 +2,6 @@ package dto
import (
"go-admin/app/admin/models"
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/common/dto"
common "go-admin/common/models"
)
@@ -24,20 +19,6 @@ func (m *SysDictDataSearch) GetNeedSearch() interface{} {
return *m
}
func (m *SysDictDataSearch) 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
}
func (m *SysDictDataSearch) Generate() dto.Index {
o := *m
return &o
}
type SysDictDataControl struct {
Id int `uri:"dictCode" comment:""`
DictSort int `json:"dictSort" comment:""`
@@ -78,19 +59,6 @@ type SysDictDataById struct {
common.ControlBy
}
func (s *SysDictDataById) Bind(ctx *gin.Context) error {
if ctx.Request.Method == http.MethodDelete {
err := ctx.ShouldBind(&s.Ids)
if err != nil {
return err
}
if len(s.Ids) > 0 {
return nil
}
}
return ctx.ShouldBindUri(s)
}
func (s *SysDictDataById) GetId() interface{} {
if len(s.Ids) > 0 {
s.Ids = append(s.Ids, s.Id)
@@ -99,11 +67,6 @@ func (s *SysDictDataById) GetId() interface{} {
return s.Id
}
func (s *SysDictDataById) Generate() dto.Control {
cp := *s
return &cp
}
func (s *SysDictDataById) GenerateM() (common.ActiveRecord, error) {
return &models.SysDictData{}, nil
}