mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
refactor🎨: 简化数据绑定
This commit is contained in:
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
type SysApiSearch struct {
|
||||
dto.Pagination `search:"-"`
|
||||
Title string `form:"title" search:"type:exact;column:title;table:sys_api" comment:"标题"`
|
||||
Path string `form:"path" search:"type:exact;column:path;table:sys_api" comment:"地址"`
|
||||
Title string `form:"title" search:"type:contains;column:title;table:sys_api" comment:"标题"`
|
||||
Path string `form:"path" search:"type:contains;column:path;table:sys_api" comment:"地址"`
|
||||
Action string `form:"action" search:"type:exact;column:action;table:sys_api" comment:"类型"`
|
||||
ParentId string `form:"parentId" search:"type:exact;column:parent_id;table:sys_api" comment:"按钮id"`
|
||||
SysApiOrder
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/app/admin/models"
|
||||
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
@@ -25,20 +23,6 @@ func (m *SysDictTypeSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *SysDictTypeSearch) 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 *SysDictTypeSearch) Generate() dto.Index {
|
||||
o := *m
|
||||
return &o
|
||||
}
|
||||
|
||||
type SysDictTypeControl struct {
|
||||
Id int `uri:"id"`
|
||||
DictName string `json:"dictName"`
|
||||
|
||||
@@ -4,9 +4,6 @@ import (
|
||||
"go-admin/app/admin/models"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
@@ -29,15 +26,6 @@ func (m *SysLoginLogSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *SysLoginLogSearch) 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
|
||||
}
|
||||
|
||||
type SysLoginLogControl struct {
|
||||
ID int `uri:"Id" comment:"主键"` // 主键
|
||||
Username string `json:"username" comment:"用户名"`
|
||||
@@ -52,20 +40,6 @@ type SysLoginLogControl struct {
|
||||
Msg string `json:"msg" comment:"信息"`
|
||||
}
|
||||
|
||||
func (s *SysLoginLogControl) 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 *SysLoginLogControl) Generate() (*models.SysLoginLog, error) {
|
||||
return &models.SysLoginLog{
|
||||
Model: common.Model{Id: s.ID},
|
||||
@@ -96,20 +70,6 @@ func (s *SysLoginLogById) GetId() interface{} {
|
||||
return s.Id
|
||||
}
|
||||
|
||||
func (s *SysLoginLogById) 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.Ids)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBind error: %s", err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SysLoginLogById) Generate() *SysLoginLogById {
|
||||
cp := *s
|
||||
return &cp
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"go-admin/app/admin/models"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
common "go-admin/common/models"
|
||||
)
|
||||
@@ -49,20 +46,6 @@ type SysOperaLogControl struct {
|
||||
UserAgent string `json:"userAgent" comment:"ua"`
|
||||
}
|
||||
|
||||
func (s *SysOperaLogControl) 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 *SysOperaLogControl) Generate() (*models.SysOperaLog, error) {
|
||||
return &models.SysOperaLog{
|
||||
Model: common.Model{Id: s.ID},
|
||||
@@ -104,20 +87,6 @@ func (s *SysOperaLogById) GetId() interface{} {
|
||||
return s.Id
|
||||
}
|
||||
|
||||
func (s *SysOperaLogById) 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.Ids)
|
||||
if err != nil {
|
||||
log.Debugf("ShouldBind error: %s", err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SysOperaLogById) SetUpdateBy(id int) {
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,6 @@ import (
|
||||
"go-admin/app/admin/models"
|
||||
common "go-admin/common/models"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
|
||||
"go-admin/common/dto"
|
||||
)
|
||||
|
||||
@@ -25,16 +22,6 @@ func (m *SysPostSearch) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
// Bind 映射上下文中的结构体数据
|
||||
func (m *SysPostSearch) 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
|
||||
}
|
||||
|
||||
// SysPostControl 增、改使用的结构体
|
||||
type SysPostControl struct {
|
||||
PostId int `uri:"id" comment:"id"` // id
|
||||
@@ -93,20 +80,6 @@ func (s *SysPostById) GetId() interface{} {
|
||||
return s.Id
|
||||
}
|
||||
|
||||
func (s *SysPostById) 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 *SysPostById) GenerateM() (*models.SysPost, error) {
|
||||
return &models.SysPost{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user