From 4e39e915ea13c8d16783dca3be6e21e7f12059ef Mon Sep 17 00:00:00 2001 From: linwenxiang <991154416@qq.com> Date: Mon, 31 Aug 2020 21:56:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4indexAction=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=EF=BC=8C=E5=85=81=E8=AE=B8=E7=94=A8=E6=88=B7=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=8E=A5=E6=94=B6=E7=9A=84slice=EF=BC=8C=E9=85=8D?= =?UTF-8?q?=E5=90=88gorm=E5=8F=AA=E8=83=BD=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/actions/index.go | 7 +++---- models/sysjob.go | 9 ++------- router/sysrouter.go | 5 ++++- tools/model/type.go | 1 - 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/apis/actions/index.go b/apis/actions/index.go index fa50e4f1..f8f860ee 100644 --- a/apis/actions/index.go +++ b/apis/actions/index.go @@ -2,9 +2,8 @@ package actions import ( "errors" - "go-admin/dto" - "github.com/gin-gonic/gin" + "go-admin/dto" "gorm.io/gorm" "go-admin/tools" @@ -13,8 +12,9 @@ import ( ) // IndexAction 通用查询动作 -func IndexAction(m model.ActiveRecord, d dto.Dtor) gin.HandlerFunc { +func IndexAction(m model.ActiveRecord, d dto.Dtor, f func() interface{}) gin.HandlerFunc { return func(c *gin.Context) { + list := f() object := m.Generate() req := d.Generate() var err error @@ -23,7 +23,6 @@ func IndexAction(m model.ActiveRecord, d dto.Dtor) gin.HandlerFunc { err = errors.New("db connect not exist") tools.HasError(err, "", 500) } - list := object.GenerateList() var count int64 switch idb.(type) { case *gorm.DB: diff --git a/models/sysjob.go b/models/sysjob.go index ca8cc492..473a8a58 100644 --- a/models/sysjob.go +++ b/models/sysjob.go @@ -33,20 +33,15 @@ func (e *SysJob) Generate() model.ActiveRecord { return &o } -func (e *SysJob) GenerateList() interface{} { - list := make([]SysJob, 0) - return &list -} - func (e *SysJob) GetId() interface{} { return e.JobId } -func (e *SysJob) SetCreateBy(createBy string){ +func (e *SysJob) SetCreateBy(createBy string) { e.CreateBy = createBy } -func (e *SysJob) SetUpdateBy(updateBy string){ +func (e *SysJob) SetUpdateBy(updateBy string) { e.UpdateBy = updateBy } diff --git a/router/sysrouter.go b/router/sysrouter.go index 64325532..cf4cf326 100644 --- a/router/sysrouter.go +++ b/router/sysrouter.go @@ -112,7 +112,10 @@ func registerSysJobRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlew r := v1.Group("/sysjob").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) { sysJob := &models.SysJob{} - r.GET("", actions.IndexAction(sysJob, new(dto.SysJobSearch))) + r.GET("", actions.IndexAction(sysJob, new(dto.SysJobSearch), func() interface{} { + list := make([]models.SysJob, 0) + return &list + })) r.GET("/:id", actions.ViewAction(sysJob)) r.POST("", actions.CreateAction(sysJob)) r.PUT("", actions.UpdateAction(sysJob)) diff --git a/tools/model/type.go b/tools/model/type.go index c31ad8ed..2599d1e8 100644 --- a/tools/model/type.go +++ b/tools/model/type.go @@ -8,5 +8,4 @@ type ActiveRecord interface { SetUpdateBy(updateBy string) Generate() ActiveRecord GetId() interface{} - GenerateList() interface{} }