-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
46 lines (40 loc) · 940 Bytes
/
user.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
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"
)
type User struct {
ent.Schema
}
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("sub").NotEmpty(),
field.String("iss").NotEmpty(),
field.String("name").NotEmpty(),
field.String("email").Optional().Nillable(),
field.String("picture").Optional().Nillable(),
}
}
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("groups", Group.Type),
edge.From("requests", Request.Type).Ref("created_by"),
edge.From("reviews", Review.Type).Ref("created_by"),
}
}
func (User) Indexes() []ent.Index {
return []ent.Index{
// User is uniquely identified by the issuer (iss) and the issuer's
// subject identifier (sub)
index.Fields("sub", "iss").
Unique(),
}
}
func (User) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.Time{},
}
}