/
e_menu_action.go
64 lines (53 loc) · 1.69 KB
/
e_menu_action.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package entity
import (
"context"
"github.com/tanjiancheng/gin-amis-admin/internal/app/schema"
"github.com/tanjiancheng/gin-amis-admin/pkg/util"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
// GetMenuActionCollection 获取MenuAction存储
func GetMenuActionCollection(ctx context.Context, cli *mongo.Client) *mongo.Collection {
return GetCollection(ctx, cli, MenuAction{})
}
// SchemaMenuAction 菜单动作
type SchemaMenuAction schema.MenuAction
// ToMenuAction 转换为菜单动作实体
func (a SchemaMenuAction) ToMenuAction() *MenuAction {
item := new(MenuAction)
util.StructMapToStruct(a, item)
return item
}
// MenuAction 菜单动作实体
type MenuAction struct {
Model `bson:",inline"`
MenuID string `bson:"menu_id"` // 菜单ID
Code string `bson:"code"` // 动作编号
Name string `bson:"name"` // 动作名称
}
// CollectionName 集合名
func (a MenuAction) CollectionName() string {
return a.Model.CollectionName("menu_action")
}
// CreateIndexes 创建索引
func (a MenuAction) CreateIndexes(ctx context.Context, cli *mongo.Client) error {
return a.Model.CreateIndexes(ctx, cli, a, []mongo.IndexModel{
{Keys: bson.M{"menu_id": 1}},
})
}
// ToSchemaMenuAction 转换为菜单动作对象
func (a MenuAction) ToSchemaMenuAction() *schema.MenuAction {
item := new(schema.MenuAction)
util.StructMapToStruct(a, item)
return item
}
// MenuActions 菜单动作列表
type MenuActions []*MenuAction
// ToSchemaMenuActions 转换为菜单动作对象列表
func (a MenuActions) ToSchemaMenuActions() []*schema.MenuAction {
list := make([]*schema.MenuAction, len(a))
for i, item := range a {
list[i] = item.ToSchemaMenuAction()
}
return list
}