forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
79 lines (66 loc) · 1.7 KB
/
api.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package table
import (
"fmt"
"github.com/yaoapp/gou"
"github.com/yaoapp/yao/share"
)
// apiSearchDefault search 接口默认值
func apiSearchDefault(model *gou.Model, withs map[string]gou.With) share.API {
query := gou.QueryParam{}
if model.MetaData.Option.Timestamps {
query.Orders = []gou.QueryOrder{
{Column: "created_at", Option: "desc"},
}
}
if withs != nil {
query.Withs = withs
}
return share.API{
Name: "search",
// Guard: "bearer-jwt",
Process: fmt.Sprintf("models.%s.Paginate", model.Name),
Default: []interface{}{query, 1, 20},
}
}
// apiFindDefault find 接口默认值
func apiFindDefault(model *gou.Model, withs map[string]gou.With) share.API {
query := gou.QueryParam{}
if withs != nil {
query.Withs = withs
}
return share.API{
Name: "find",
// Guard: "bearer-jwt",
Process: fmt.Sprintf("models.%s.Find", model.Name),
Default: []interface{}{nil, query},
}
}
// apiDefault 接口默认值
func apiDefault(model *gou.Model, name string, process string) share.API {
return share.API{
Name: name,
// Guard: "bearer-jwt",
Process: fmt.Sprintf("models.%s.%s", model.Name, process),
}
}
// apiFindDefault 接口默认值
func apiDefaultWhere(model *gou.Model, withs map[string]gou.With, name string, process string) share.API {
query := gou.QueryParam{}
if withs != nil {
query.Withs = withs
}
return share.API{
Name: name,
// Guard: "bearer-jwt",
Process: fmt.Sprintf("models.%s.%s", model.Name, process),
Default: []interface{}{query},
}
}
// apiDefaultSetting 数据表格配置默认值
func apiDefaultSetting() share.API {
return share.API{
Name: "setting",
// Guard: "bearer-jwt",
Process: fmt.Sprintf("xiang.table.setting"),
}
}