refactor🎨: 简化数据绑定
This commit is contained in:
1 parent
190dcfedc0
commit
3be02f1364
6 files changed
+3
-154
No files matched your search
@@ -8,8 +8,8 @@ import (
|
|||||||
|
|
||||||
type SysApiSearch struct {
|
type SysApiSearch struct {
|
||||||
dto.Pagination `search:"-"`
|
dto.Pagination `search:"-"`
|
||||||
Title string `form:"title" search:"type:exact;column:title;table:sys_api" comment:"标题"`
|
Title string `form:"title" search:"type:contains;column:title;table:sys_api" comment:"标题"`
|
||||||
Path string `form:"path" search:"type:exact;column:path;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:"类型"`
|
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"`
|
ParentId string `form:"parentId" search:"type:exact;column:parent_id;table:sys_api" comment:"按钮id"`
|
||||||
SysApiOrder
|
SysApiOrder
|
||||||
|
|||||||
@@ -2,11 +2,6 @@ package dto
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"go-admin/app/admin/models"
|
"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"
|
"go-admin/common/dto"
|
||||||
common "go-admin/common/models"
|
common "go-admin/common/models"
|
||||||
)
|
)
|
||||||
@@ -24,20 +19,6 @@ func (m *SysDictDataSearch) GetNeedSearch() interface{} {
|
|||||||
return *m
|
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 {
|
type SysDictDataControl struct {
|
||||||
Id int `uri:"dictCode" comment:""`
|
Id int `uri:"dictCode" comment:""`
|
||||||
DictSort int `json:"dictSort" comment:""`
|
DictSort int `json:"dictSort" comment:""`
|
||||||
@@ -78,19 +59,6 @@ type SysDictDataById struct {
|
|||||||
common.ControlBy
|
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{} {
|
func (s *SysDictDataById) GetId() interface{} {
|
||||||
if len(s.Ids) > 0 {
|
if len(s.Ids) > 0 {
|
||||||
s.Ids = append(s.Ids, s.Id)
|
s.Ids = append(s.Ids, s.Id)
|
||||||
@@ -99,11 +67,6 @@ func (s *SysDictDataById) GetId() interface{} {
|
|||||||
return s.Id
|
return s.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SysDictDataById) Generate() dto.Control {
|
|
||||||
cp := *s
|
|
||||||
return &cp
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SysDictDataById) GenerateM() (common.ActiveRecord, error) {
|
func (s *SysDictDataById) GenerateM() (common.ActiveRecord, error) {
|
||||||
return &models.SysDictData{}, nil
|
return &models.SysDictData{}, nil
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"go-admin/app/admin/models"
|
"go-admin/app/admin/models"
|
||||||
|
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
|
||||||
"go-admin/common/dto"
|
"go-admin/common/dto"
|
||||||
common "go-admin/common/models"
|
common "go-admin/common/models"
|
||||||
)
|
)
|
||||||
@@ -25,20 +23,6 @@ func (m *SysDictTypeSearch) GetNeedSearch() interface{} {
|
|||||||
return *m
|
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 {
|
type SysDictTypeControl struct {
|
||||||
Id int `uri:"id"`
|
Id int `uri:"id"`
|
||||||
DictName string `json:"dictName"`
|
DictName string `json:"dictName"`
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ import (
|
|||||||
"go-admin/app/admin/models"
|
"go-admin/app/admin/models"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
|
||||||
|
|
||||||
"go-admin/common/dto"
|
"go-admin/common/dto"
|
||||||
common "go-admin/common/models"
|
common "go-admin/common/models"
|
||||||
)
|
)
|
||||||
@@ -29,15 +26,6 @@ func (m *SysLoginLogSearch) GetNeedSearch() interface{} {
|
|||||||
return *m
|
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 {
|
type SysLoginLogControl struct {
|
||||||
ID int `uri:"Id" comment:"主键"` // 主键
|
ID int `uri:"Id" comment:"主键"` // 主键
|
||||||
Username string `json:"username" comment:"用户名"`
|
Username string `json:"username" comment:"用户名"`
|
||||||
@@ -52,20 +40,6 @@ type SysLoginLogControl struct {
|
|||||||
Msg string `json:"msg" comment:"信息"`
|
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) {
|
func (s *SysLoginLogControl) Generate() (*models.SysLoginLog, error) {
|
||||||
return &models.SysLoginLog{
|
return &models.SysLoginLog{
|
||||||
Model: common.Model{Id: s.ID},
|
Model: common.Model{Id: s.ID},
|
||||||
@@ -96,20 +70,6 @@ func (s *SysLoginLogById) GetId() interface{} {
|
|||||||
return s.Id
|
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 {
|
func (s *SysLoginLogById) Generate() *SysLoginLogById {
|
||||||
cp := *s
|
cp := *s
|
||||||
return &cp
|
return &cp
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
package dto
|
package dto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go-admin/app/admin/models"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"go-admin/app/admin/models"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
|
||||||
|
|
||||||
"go-admin/common/dto"
|
"go-admin/common/dto"
|
||||||
common "go-admin/common/models"
|
common "go-admin/common/models"
|
||||||
)
|
)
|
||||||
@@ -49,20 +46,6 @@ type SysOperaLogControl struct {
|
|||||||
UserAgent string `json:"userAgent" comment:"ua"`
|
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) {
|
func (s *SysOperaLogControl) Generate() (*models.SysOperaLog, error) {
|
||||||
return &models.SysOperaLog{
|
return &models.SysOperaLog{
|
||||||
Model: common.Model{Id: s.ID},
|
Model: common.Model{Id: s.ID},
|
||||||
@@ -104,20 +87,6 @@ func (s *SysOperaLogById) GetId() interface{} {
|
|||||||
return s.Id
|
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) {
|
func (s *SysOperaLogById) SetUpdateBy(id int) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,6 @@ import (
|
|||||||
"go-admin/app/admin/models"
|
"go-admin/app/admin/models"
|
||||||
common "go-admin/common/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"
|
"go-admin/common/dto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,16 +22,6 @@ func (m *SysPostSearch) GetNeedSearch() interface{} {
|
|||||||
return *m
|
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 增、改使用的结构体
|
// SysPostControl 增、改使用的结构体
|
||||||
type SysPostControl struct {
|
type SysPostControl struct {
|
||||||
PostId int `uri:"id" comment:"id"` // id
|
PostId int `uri:"id" comment:"id"` // id
|
||||||
@@ -93,20 +80,6 @@ func (s *SysPostById) GetId() interface{} {
|
|||||||
return s.Id
|
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) {
|
func (s *SysPostById) GenerateM() (*models.SysPost, error) {
|
||||||
return &models.SysPost{}, nil
|
return &models.SysPost{}, nil
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user