-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
45 lines (39 loc) · 958 Bytes
/
response.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
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"
)
// Response holds the schema definition for the Response entity.
type Response struct {
ent.Schema
}
// Fields of the Response.
func (Response) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Default(uuid.New),
field.Int("value").Default(0),
field.JSON("meta", make(map[string]interface{})).Optional(),
}
}
// Edges of the Response.
func (Response) Edges() []ent.Edge {
return []ent.Edge{
// belongs to
edge.From("item", Item.Type).Ref("responses").Unique().Required(),
edge.From("take", Take.Type).Ref("responses").Unique().Required(),
}
}
func (Response) Indexes() []ent.Index {
return []ent.Index{
index.Edges("item", "take").Unique(),
}
}
func (Response) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.Time{},
}
}