调整indexAction路径,允许用户自定义接收的slice,配合gorm只能搜索

This commit is contained in:
linwenxiang committed 2020-08-31 21:56:29 +08:00
1 parent b98997a69f
commit 4e39e915ea
4 files changed
+9 -13

No files matched your search

+3 -4
View File
@@ -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:
+2 -7
View File
@@ -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
}
+4 -1
View File
@@ -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))
-1
View File
@@ -8,5 +8,4 @@ type ActiveRecord interface {
SetUpdateBy(updateBy string)
Generate() ActiveRecord
GetId() interface{}
GenerateList() interface{}
}