-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
50 lines (43 loc) · 1.09 KB
/
request.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
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"entgo.io/ent/schema/mixin"
"github.com/google/uuid"
)
type RequestSpec map[string]interface{}
type Request struct {
ent.Schema
}
func (Request) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New),
field.String("kind").NotEmpty(),
field.String("description").NotEmpty(),
field.Enum("status").Values("pending_approval", "rejected", "approved").Default("pending_approval"),
field.JSON("spec", RequestSpec{}),
}
}
func (Request) Edges() []ent.Edge {
return []ent.Edge{
edge.To("project", Project.Type).Required().Unique(),
edge.To("service", Service.Type).Required().Unique(),
edge.To("created_by", User.Type).Required().Unique(),
edge.From("reviews", Review.Type).Ref("request"),
edge.From("Triggers", Trigger.Type).Ref("Request"),
}
}
func (Request) Indexes() []ent.Index {
return []ent.Index{
index.Fields("id").
Unique(),
}
}
func (Request) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.Time{},
}
}