feat : update actions gen
This commit is contained in:
1 parent
aaba20d42a
commit
fa07a57d22
14 files changed
+160
-112
No files matched your search
@@ -0,0 +1,96 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/common/dto"
|
||||
models2 "go-admin/common/models"
|
||||
)
|
||||
|
||||
type {{.ClassName}}Search struct {
|
||||
dto.Pagination `search:"-"`
|
||||
{{ $tablename := .TBName -}}
|
||||
{{ range .Columns -}}
|
||||
{{$z := .IsQuery}}
|
||||
{{- if ($z) -}}
|
||||
{{.GoField}} {{.GoType}} `form:"{{.JsonField}}" search:"type:{{if eq .QueryType "EQ"}}exact{{ else if eq .QueryType "NE"}}iexact{{ else if eq .QueryType "LIKE"}}contains{{ else if eq .QueryType "GT"}}gt{{ else if eq .QueryType "GTE"}}gte{{ else if eq .QueryType "LT"}}lt{{ else if eq .QueryType "LTE"}}lte{{- end }};column:{{.ColumnName}};table:{{$tablename}}"` // {{.ColumnComment}}
|
||||
|
||||
{{ end -}}
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
func (m *{{.ClassName}}Search) GetNeedSearch() interface{} {
|
||||
return *m
|
||||
}
|
||||
|
||||
func (m *{{.ClassName}}Search) Bind(ctx *gin.Context) error {
|
||||
return ctx.Bind(m)
|
||||
}
|
||||
|
||||
func (m *{{.ClassName}}Search) Generate() dto.Index {
|
||||
o := *m
|
||||
return &o
|
||||
}
|
||||
|
||||
func (m *{{.ClassName}}Search) GetPageIndex() int {
|
||||
return m.PageIndex
|
||||
}
|
||||
|
||||
func (m *{{.ClassName}}Search) GetPageSize() int {
|
||||
return m.PageSize
|
||||
}
|
||||
|
||||
type {{.ClassName}}Control struct {
|
||||
{{ range .Columns -}}
|
||||
{{$x := .Pk}}
|
||||
{{- if ($x) }}
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}""` // {{.ColumnComment}}
|
||||
{{- else if eq .GoField "CreatedAt" -}}
|
||||
{{- else if eq .GoField "UpdatedAt" -}}
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else }}
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}""` // {{.ColumnComment}}{{end -}}
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
func (s *{{.ClassName}}Control) Bind(ctx *gin.Context) error {
|
||||
return ctx.Bind(s)
|
||||
}
|
||||
|
||||
func (s *{{.ClassName}}Control) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *{{.ClassName}}Control) GenerateM() (models2.ActiveRecord, error) {
|
||||
return &models.{{.ClassName}}{
|
||||
{{ range .Columns -}}
|
||||
{{$x := .Pk}}
|
||||
{{- if ($x) }}
|
||||
{{.GoField}}: s.{{.GoField}},
|
||||
{{- else if eq .GoField "CreatedAt" -}}
|
||||
{{- else if eq .GoField "UpdatedAt" -}}
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else }}
|
||||
{{.GoField}}: s.{{.GoField}},
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *{{.ClassName}}Control) GetId() interface{} {
|
||||
return s.{{.PkGoField}}
|
||||
}
|
||||
|
||||
type {{.ClassName}}ById struct {
|
||||
dto.ObjectById
|
||||
}
|
||||
|
||||
func (s *{{.ClassName}}ById) Generate() dto.Control {
|
||||
cp := *s
|
||||
return &cp
|
||||
}
|
||||
|
||||
func (s *{{.ClassName}}ById) GenerateM() (models2.ActiveRecord, error) {
|
||||
return &models.{{.ClassName}}{}, nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
{{- if eq .IsActions true -}}
|
||||
{{- else }}
|
||||
"go-admin/common/dto"
|
||||
"go-admin/tools"
|
||||
orm "go-admin/common/global"
|
||||
{{ end }}
|
||||
"go-admin/common/models"
|
||||
)
|
||||
|
||||
type {{.ClassName}} struct {
|
||||
{{ range .Columns -}}
|
||||
{{$x := .Pk}}
|
||||
{{- if ($x) }}
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key;AUTO_INCREMENT;comment:{{.ColumnComment}}"` // {{.ColumnComment}}
|
||||
{{- else if eq .GoField "CreatedAt" -}}
|
||||
{{- else if eq .GoField "UpdatedAt" -}}
|
||||
{{- else if eq .GoField "DeletedAt" -}}
|
||||
{{- else }}
|
||||
{{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{.ColumnComment}}"` // {{.ColumnComment}}{{end -}}
|
||||
{{- end }}
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
func ({{.ClassName}}) TableName() string {
|
||||
return "{{.TBName}}"
|
||||
}
|
||||
|
||||
func (e *{{.ClassName}}) Generate() models.ActiveRecord {
|
||||
o := *e
|
||||
return &o
|
||||
}
|
||||
|
||||
func (e *{{.ClassName}}) GetId() interface{} {
|
||||
return e.{{.PkGoField}}
|
||||
}
|
||||
|
||||
func (e *{{.ClassName}}) SetCreateBy(createBy uint) {
|
||||
e.CreateBy = strconv.Itoa(int(createBy))
|
||||
}
|
||||
|
||||
func (e *{{.ClassName}}) SetUpdateBy(updateBy uint) {
|
||||
e.UpdateBy = strconv.Itoa(int(updateBy))
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"go-admin/app/admin/middleware"
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/app/admin/service/dto"
|
||||
"go-admin/common/actions"
|
||||
jwt "go-admin/pkg/jwtauth"
|
||||
)
|
||||
|
||||
func init() {
|
||||
routerCheckRole = append(routerCheckRole, register{{.ClassName}}Router)
|
||||
}
|
||||
|
||||
// 需认证的路由代码
|
||||
func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
r := v1.Group("/{{.ModuleName}}").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
model := &models.{{.ClassName}}{}
|
||||
r.GET("", actions.PermissionAction(), actions.IndexAction(model, new(dto.{{.ClassName}}Search), func() interface{} {
|
||||
list := make([]models.{{.ClassName}}, 0)
|
||||
return &list
|
||||
}))
|
||||
r.GET("/:id", actions.PermissionAction(), actions.ViewAction(new(dto.{{.ClassName}}ById)))
|
||||
r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control)))
|
||||
r.PUT("/:id", actions.PermissionAction(), actions.UpdateAction(new(dto.{{.ClassName}}Control)))
|
||||
r.DELETE("/:id", actions.PermissionAction(), actions.DeleteAction(new(dto.{{.ClassName}}ById)))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"go-admin/app/admin/middleware"
|
||||
"go-admin/app/admin/models"
|
||||
"go-admin/app/admin/service/dto"
|
||||
"go-admin/common/actions"
|
||||
)
|
||||
|
||||
// 无需认证的路由代码
|
||||
func register{{.ClassName}}Router(v1 *gin.RouterGroup) {
|
||||
r := v1.Group("/{{.ModuleName}}")
|
||||
{
|
||||
model := &models.{{.ClassName}}{}
|
||||
r.GET("", actions.IndexAction(model, new(dto.{{.ClassName}}Search), func() interface{} {
|
||||
list := make([]models.{{.ClassName}}, 0)
|
||||
return &list
|
||||
}))
|
||||
r.GET("/:id", actions.ViewAction(new(dto.{{.ClassName}}ById)))
|
||||
r.POST("", actions.CreateAction(new(dto.{{.ClassName}}Control)))
|
||||
r.PUT("/:id", actions.UpdateAction(new(dto.{{.ClassName}}Control)))
|
||||
r.DELETE("/:id", actions.DeleteAction(new(dto.{{.ClassName}}ById)))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user