Skip to content

Commit 936270c

Browse files
committed
Merge branch 'main' of github.com:gin-admin/gin-admin-cli
2 parents ad0a828 + 7d93120 commit 936270c

8 files changed

Lines changed: 32 additions & 20 deletions

File tree

examples/menu.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
- name: ID
6262
type: string
6363
comment: Unique ID
64-
gorm_tag: "size:20;primarykey"
64+
gorm_tag: "size:20;primaryKey"
6565
- name: MenuID
6666
type: string
6767
comment: From Menu.ID

examples/role.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
- name: ID
3939
type: string
4040
comment: Unique ID
41-
gorm_tag: "size:20;primarykey"
41+
gorm_tag: "size:20;primaryKey"
4242
- name: RoleID
4343
type: string
4444
comment: From Role.ID

examples/user.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
- name: ID
6060
type: string
6161
comment: Unique ID
62-
gorm_tag: "size:20;primarykey"
62+
gorm_tag: "size:20;primaryKey"
6363
- name: UserID
6464
type: string
6565
comment: From User.ID

internal/parser/tpl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func (a *$$ModuleName$$) Init(ctx context.Context) error {
2828
}
2929
3030
func (a *$$ModuleName$$) RegisterV1Routers(ctx context.Context, v1 *gin.RouterGroup) error {
31+
v1 = v1.Group("$$LowerModuleName$$")
3132
return nil
3233
}
3334

internal/schema/struct.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (a *S) Format() *S {
4848
fields = append(fields, &Field{
4949
Name: "ID",
5050
Type: "string",
51-
GormTag: "size:20;primarykey;",
51+
GormTag: "size:20;primaryKey;",
5252
Comment: "Unique ID",
5353
})
5454
fields = append(fields, a.Fields...)

tpls/default/api.go.tpl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type {{$name}} struct {
1414
{{$name}}BIZ *biz.{{$name}}
1515
}
1616

17+
// Query
1718
// @Tags {{$name}}API
1819
// @Security ApiKeyAuth
1920
// @Summary Query {{lowerSpace .Name}} list
@@ -31,7 +32,7 @@ type {{$name}} struct {
3132
// @Success 200 {object} util.ResponseResult{data=[]schema.{{$name}}}
3233
// @Failure 401 {object} util.ResponseResult
3334
// @Failure 500 {object} util.ResponseResult
34-
// @Router /api/v1/{{lowerHyphensPlural .Name}} [get]
35+
// @Router /api/v1/{{lower .ModuleName}}/{{lowerHyphensPlural .Name}} [get]
3536
func (a *{{$name}}) Query(c *gin.Context) {
3637
ctx := c.Request.Context()
3738
var params schema.{{$name}}QueryParam
@@ -48,14 +49,15 @@ func (a *{{$name}}) Query(c *gin.Context) {
4849
util.ResPage(c, result.Data, result.PageResult)
4950
}
5051

52+
// Get
5153
// @Tags {{$name}}API
5254
// @Security ApiKeyAuth
5355
// @Summary Get {{lowerSpace .Name}} record by ID
5456
// @Param id path string true "unique id"
5557
// @Success 200 {object} util.ResponseResult{data=schema.{{$name}}}
5658
// @Failure 401 {object} util.ResponseResult
5759
// @Failure 500 {object} util.ResponseResult
58-
// @Router /api/v1/{{lowerHyphensPlural .Name}}/{id} [get]
60+
// @Router /api/v1/{{lower .ModuleName}}/{{lowerHyphensPlural .Name}}/{id} [get]
5961
func (a *{{$name}}) Get(c *gin.Context) {
6062
ctx := c.Request.Context()
6163
item, err := a.{{$name}}BIZ.Get(ctx, c.Param("id"))
@@ -66,6 +68,7 @@ func (a *{{$name}}) Get(c *gin.Context) {
6668
util.ResSuccess(c, item)
6769
}
6870

71+
// Create
6972
// @Tags {{$name}}API
7073
// @Security ApiKeyAuth
7174
// @Summary Create {{lowerSpace .Name}} record
@@ -74,7 +77,7 @@ func (a *{{$name}}) Get(c *gin.Context) {
7477
// @Failure 400 {object} util.ResponseResult
7578
// @Failure 401 {object} util.ResponseResult
7679
// @Failure 500 {object} util.ResponseResult
77-
// @Router /api/v1/{{lowerHyphensPlural .Name}} [post]
80+
// @Router /api/v1/{{lower .ModuleName}}/{{lowerHyphensPlural .Name}} [post]
7881
func (a *{{$name}}) Create(c *gin.Context) {
7982
ctx := c.Request.Context()
8083
item := new(schema.{{$name}}Form)
@@ -94,6 +97,7 @@ func (a *{{$name}}) Create(c *gin.Context) {
9497
util.ResSuccess(c, result)
9598
}
9699

100+
// Update
97101
// @Tags {{$name}}API
98102
// @Security ApiKeyAuth
99103
// @Summary Update {{lowerSpace .Name}} record by ID
@@ -103,7 +107,7 @@ func (a *{{$name}}) Create(c *gin.Context) {
103107
// @Failure 400 {object} util.ResponseResult
104108
// @Failure 401 {object} util.ResponseResult
105109
// @Failure 500 {object} util.ResponseResult
106-
// @Router /api/v1/{{lowerHyphensPlural .Name}}/{id} [put]
110+
// @Router /api/v1/{{lower .ModuleName}}/{{lowerHyphensPlural .Name}}/{id} [put]
107111
func (a *{{$name}}) Update(c *gin.Context) {
108112
ctx := c.Request.Context()
109113
item := new(schema.{{$name}}Form)
@@ -123,14 +127,15 @@ func (a *{{$name}}) Update(c *gin.Context) {
123127
util.ResOK(c)
124128
}
125129

130+
// Delete
126131
// @Tags {{$name}}API
127132
// @Security ApiKeyAuth
128133
// @Summary Delete {{lowerSpace .Name}} record by ID
129134
// @Param id path string true "unique id"
130135
// @Success 200 {object} util.ResponseResult
131136
// @Failure 401 {object} util.ResponseResult
132137
// @Failure 500 {object} util.ResponseResult
133-
// @Router /api/v1/{{lowerHyphensPlural .Name}}/{id} [delete]
138+
// @Router /api/v1/{{lower .ModuleName}}/{{lowerHyphensPlural .Name}}/{id} [delete]
134139
func (a *{{$name}}) Delete(c *gin.Context) {
135140
ctx := c.Request.Context()
136141
err := a.{{$name}}BIZ.Delete(ctx, c.Param("id"))

tpls/default/dal.go.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
{{$includeStatus := .Include.Status}}
1515
{{$treeTpl := eq .TplType "tree"}}
1616

17-
// Get {{lowerSpace .Name}} storage instance
17+
// Get{{$name}}DB Get {{lowerSpace .Name}} storage instance
1818
func Get{{$name}}DB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
1919
return util.GetDB(ctx, defDB).Model(new(schema.{{$name}}))
2020
}
@@ -77,7 +77,7 @@ func (a *{{$name}}) Get(ctx context.Context, id string, opts ...schema.{{$name}}
7777
return item, nil
7878
}
7979

80-
// Exist checks if the specified {{lowerSpace .Name}} exists in the database.
80+
// Exists checks if the specified {{lowerSpace .Name}} exists in the database.
8181
func (a *{{$name}}) Exists(ctx context.Context, id string) (bool, error) {
8282
ok, err := util.Exists(ctx, Get{{$name}}DB(ctx, a.DB).Where("id=?", id))
8383
return ok, errors.WithStack(err)
@@ -120,14 +120,14 @@ func (a *{{$name}}) Delete(ctx context.Context, id string) error {
120120
}
121121

122122
{{- if $treeTpl}}
123-
// Updates the parent path of the specified {{lowerSpace .Name}}.
123+
// UpdateParentPath Updates the parent path of the specified {{lowerSpace .Name}}.
124124
func (a *{{$name}}) UpdateParentPath(ctx context.Context, id, parentPath string) error {
125125
result := Get{{$name}}DB(ctx, a.DB).Where("id=?", id).Update("parent_path", parentPath)
126126
return errors.WithStack(result.Error)
127127
}
128128

129129
{{- if $includeStatus}}
130-
// Updates the status of all {{lowerPlural .Name}} whose parent path starts with the provided parent path.
130+
// UpdateStatusByParentPath Updates the status of all {{lowerPlural .Name}} whose parent path starts with the provided parent path.
131131
func (a *{{$name}}) UpdateStatusByParentPath(ctx context.Context, parentPath, status string) error {
132132
result := Get{{$name}}DB(ctx, a.DB).Where("parent_path like ?", parentPath+"%").Update("status", status)
133133
return errors.WithStack(result.Error)

tpls/default/schema.go.tpl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type {{$name}} struct {
1717
{{- end}}
1818
}
1919

20-
// Defining the query parameters for the `{{$name}}` struct.
20+
// {{$name}}QueryParam Defining the query parameters for the `{{$name}}` struct.
2121
type {{$name}}QueryParam struct {
2222
util.PaginationParam
2323
{{if $treeTpl}}InIDs []string `form:"-"`{{- end}}
@@ -28,38 +28,42 @@ type {{$name}}QueryParam struct {
2828
{{- end}}
2929
}
3030

31-
// Defining the query options for the `{{$name}}` struct.
31+
// {{$name}}QueryOptions Defining the query options for the `{{$name}}` struct.
3232
type {{$name}}QueryOptions struct {
3333
util.QueryOptions
3434
}
3535

36-
// Defining the query result for the `{{$name}}` struct.
36+
// {{$name}}QueryResult Defining the query result for the `{{$name}}` struct.
3737
type {{$name}}QueryResult struct {
3838
Data {{plural .Name}}
3939
PageResult *util.PaginationResult
4040
}
4141

42-
// Defining the slice of `{{$name}}` struct.
42+
// {{plural .Name}} Defining the slice of `{{$name}}` struct.
4343
type {{plural .Name}} []*{{$name}}
4444

4545
{{- if $includeSequence}}
46+
// Len
4647
func (a {{plural .Name}}) Len() int {
4748
return len(a)
4849
}
4950

51+
// Less
5052
func (a {{plural .Name}}) Less(i, j int) bool {
5153
if a[i].Sequence == a[j].Sequence {
5254
return a[i].CreatedAt.Unix() > a[j].CreatedAt.Unix()
5355
}
5456
return a[i].Sequence > a[j].Sequence
5557
}
5658

59+
// Swap
5760
func (a {{plural .Name}}) Swap(i, j int) {
5861
a[i], a[j] = a[j], a[i]
5962
}
6063
{{- end}}
6164

6265
{{- if $treeTpl}}
66+
// ToMap
6367
func (a {{plural .Name}}) ToMap() map[string]*{{$name}} {
6468
m := make(map[string]*{{$name}})
6569
for _, item := range a {
@@ -68,6 +72,7 @@ func (a {{plural .Name}}) ToMap() map[string]*{{$name}} {
6872
return m
6973
}
7074

75+
// SplitParentIDs
7176
func (a {{plural .Name}}) SplitParentIDs() []string {
7277
parentIDs := make([]string, 0, len(a))
7378
idMapper := make(map[string]struct{})
@@ -92,6 +97,7 @@ func (a {{plural .Name}}) SplitParentIDs() []string {
9297
return parentIDs
9398
}
9499

100+
// ToTree
95101
func (a {{plural .Name}}) ToTree() {{plural .Name}} {
96102
var list {{plural .Name}}
97103
m := a.ToMap()
@@ -113,7 +119,7 @@ func (a {{plural .Name}}) ToTree() {{plural .Name}} {
113119
}
114120
{{- end}}
115121

116-
// Defining the data structure for creating a `{{$name}}` struct.
122+
// {{$name}}Form Defining the data structure for creating a `{{$name}}` struct.
117123
type {{$name}}Form struct {
118124
{{- range .Fields}}{{$fieldName := .Name}}{{$type :=.Type}}
119125
{{- with .Form}}
@@ -122,12 +128,12 @@ type {{$name}}Form struct {
122128
{{- end}}
123129
}
124130

125-
// A validation function for the `{{$name}}Form` struct.
131+
// Validate A validation function for the `{{$name}}Form` struct.
126132
func (a *{{$name}}Form) Validate() error {
127133
return nil
128134
}
129135

130-
// Convert `{{$name}}Form` to `{{$name}}` object.
136+
// FillTo Convert `{{$name}}Form` to `{{$name}}` object.
131137
func (a *{{$name}}Form) FillTo({{lowerCamel $name}} *{{$name}}) error {
132138
{{- range .Fields}}{{$fieldName := .Name}}
133139
{{- with .Form}}

0 commit comments

Comments
 (0)