-
Notifications
You must be signed in to change notification settings - Fork 34
/
publisher_models.go
108 lines (96 loc) · 2.54 KB
/
publisher_models.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package publisher
import (
"github.com/machinefi/w3bstream/pkg/depends/base/types"
"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder"
"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/datatypes"
"github.com/machinefi/w3bstream/pkg/models"
)
type CreateReq struct {
Name string `json:"name"`
Key string `json:"key"`
}
type UpdateReq struct {
PublisherID types.SFID `json:"-"`
Name string `json:"name"`
Key string `json:"key"`
}
type CondArgs struct {
ProjectIDs []types.SFID `name:"-"`
PublisherIDs []types.SFID `in:"query" name:"publisherIDs,omitempty"`
Names []string `in:"query" name:"name,omitempty"`
Keys []string `in:"query" name:"key,omitempty"`
NameLike string `in:"query" name:"name,omitempty"`
LNameLike string `in:"query" name:"lname,omitempty"`
RNameLike string `in:"query" name:"rname,omitempty"`
}
func (r *CondArgs) Condition() builder.SqlCondition {
var (
m = &models.Publisher{}
c []builder.SqlCondition
)
if len(r.ProjectIDs) > 0 {
if len(r.ProjectIDs) == 1 {
c = append(c, m.ColProjectID().Eq(r.ProjectIDs[0]))
} else {
c = append(c, m.ColProjectID().In(r.ProjectIDs))
}
}
if len(r.PublisherIDs) > 0 {
if len(r.PublisherIDs) == 1 {
c = append(c, m.ColPublisherID().Eq(r.PublisherIDs[0]))
} else {
c = append(c, m.ColPublisherID().In(r.PublisherIDs))
}
}
if len(r.Names) > 0 {
if len(r.PublisherIDs) == 1 {
c = append(c, m.ColName().Eq(r.Names[0]))
} else {
c = append(c, m.ColName().In(r.Names))
}
}
if len(r.Keys) > 0 {
if len(r.PublisherIDs) == 1 {
c = append(c, m.ColKey().Eq(r.Keys[0]))
} else {
c = append(c, m.ColKey().In(r.Keys))
}
}
if r.NameLike != "" {
c = append(c, m.ColName().Like(r.NameLike))
}
if r.LNameLike != "" {
c = append(c, m.ColName().LLike(r.LNameLike))
}
if r.RNameLike != "" {
c = append(c, m.ColName().RLike(r.RNameLike))
}
return builder.And(c...)
}
type ListReq struct {
CondArgs
datatypes.Pager
}
func (r *ListReq) Additions() builder.Additions {
m := &models.Publisher{}
return builder.Additions{
builder.OrderBy(
builder.DescOrder(m.ColUpdatedAt()),
builder.DescOrder(m.ColCreatedAt()),
),
r.Pager.Addition(),
}
}
type ListRsp struct {
Data []models.Publisher `json:"data"`
Total int64 `json:"total"`
}
type Detail struct {
ProjectName string `json:"projectName" db:"f_project_name"`
models.Publisher
datatypes.OperationTimes
}
type ListDetailRsp struct {
Total int64 `json:"total"`
Data []*Detail `json:"data"`
}