/
event.go
123 lines (105 loc) · 3.74 KB
/
event.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package schema
import (
"time"
"github.com/facebookincubator/ent"
"github.com/facebookincubator/ent/schema/edge"
"github.com/facebookincubator/ent/schema/field"
)
// Event holds the schema definition for the Event entity.
type Event struct {
ent.Schema
}
// EventKind is not great for readability but we did this so we do not have to define the Enum
// values twice. Below in the Kind field we need to pack the values in, this provides a way to do
// that by making an array.
type EventKind string
var eventKinds []string
func newEventKind(value string) EventKind {
eventKinds = append(eventKinds, value)
return EventKind(value)
}
// IF you update this you MUST regen the ent stuff
var (
EventCreateJob EventKind = newEventKind("CREATE_JOB")
EventCreateTag EventKind = newEventKind("CREATE_TAG")
EventApplyTagToTask EventKind = newEventKind("APPLY_TAG_TO_TASK")
EventApplyTagToTarget EventKind = newEventKind("APPLY_TAG_TO_TARGET")
EventApplyTagToJob EventKind = newEventKind("APPLY_TAG_TO_JOB")
EventRemoveTagFromTask EventKind = newEventKind("REMOVE_TAG_FROM_TASK")
EventRemoveTagFromTarget EventKind = newEventKind("REMOVE_TAG_FROM_TARGET")
EventRemoveTagFromJob EventKind = newEventKind("REMOVE_TAG_FROM_JOB")
EventCreateTarget EventKind = newEventKind("CREATE_TARGET")
EventSetTargetFields EventKind = newEventKind("SET_TARGET_FIELDS")
EventDeleteTarget EventKind = newEventKind("DELETE_TARGET")
EventAddCredentialForTarget EventKind = newEventKind("ADD_CREDENTIAL_FOR_TARGET")
EventUploadFile EventKind = newEventKind("UPLOAD_FILE")
EventCreateLink EventKind = newEventKind("CREATE_LINK")
EventSetLinkFields EventKind = newEventKind("SET_LINK_FIELDS")
EventActivateUser EventKind = newEventKind("ACTIVATE_USER")
EventCreateUser EventKind = newEventKind("CREATE_USER")
EventMakeAdmin EventKind = newEventKind("MAKE_ADMIN")
EventRemoveAdmin EventKind = newEventKind("REMOVE_ADMIN")
EventChangeName EventKind = newEventKind("CHANGE_NAME")
EventActivateService EventKind = newEventKind("ACTIVATE_SERVICE")
EventCreateService EventKind = newEventKind("CREATE_SERVICE")
EventLikeEvent EventKind = newEventKind("LIKE_EVENT")
EventOther EventKind = newEventKind("OTHER")
)
// Fields of the Event.
func (Event) Fields() []ent.Field {
return []ent.Field{
field.Time("CreationTime").
Default(func() time.Time {
return time.Now()
}).
Comment("The timestamp for when the Job was created"),
field.Enum("Kind").
Values(eventKinds...).
Comment("The kind of event"),
}
}
// Edges of the Event.
func (Event) Edges() []ent.Edge {
return []ent.Edge{
edge.To("job", Job.Type).
Unique().
Comment("An Event can have a job"),
edge.To("file", File.Type).
Unique().
Comment("An Event can have a file"),
edge.To("credential", Credential.Type).
Unique().
Comment("An Event can have a credential"),
edge.To("link", Link.Type).
Unique().
Comment("An Event can have a link"),
edge.To("tag", Tag.Type).
Unique().
Comment("An Event can have a tag"),
edge.To("target", Target.Type).
Unique().
Comment("An Event can have a target"),
edge.To("task", Task.Type).
Unique().
Comment("An Event can have a task"),
edge.To("user", User.Type).
Unique().
Comment("An Event can have a user"),
edge.To("event", Event.Type).
Unique().
Comment("An Event can have an event"),
edge.To("service", Service.Type).
Unique().
Comment("An Event can have a service"),
edge.To("likers", User.Type).
Comment("An Event can have a few likers"),
edge.From("owner", User.Type).
Ref("events").
Unique().
Comment("An event can have a user owner"),
edge.From("svcOwner", Service.Type).
Ref("events").
Unique().
Comment("An event can have a service owner"),
}
}