-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale.go
90 lines (79 loc) · 2.09 KB
/
scale.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
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/tinygodsdev/orrery/internal/domain"
"github.com/google/uuid"
)
// Scale holds the schema definition for the Scale entity.
type Scale struct {
ent.Schema
}
// Fields of the Scale.
func (Scale) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Default(uuid.New),
field.String("code").NotEmpty().Unique().Immutable(),
field.Bool("global").Default(false),
field.Enum("type").Values(
domain.ScaleTypeSten,
domain.ScaleTypeMean,
domain.ScaleTypePerc,
domain.ScaleTypeSum,
domain.ScaleTypeZScore,
).Default(domain.ScaleTypeSten),
}
}
// Edges of the Scale.
func (Scale) Edges() []ent.Edge {
return []ent.Edge{
// has
edge.To("items", Item.Type).Through("scale_item", ScaleItem.Type),
edge.To("interpretations", Interpretation.Type),
edge.To("translations", ScaleTranslation.Type),
edge.To("norms", Norm.Type),
edge.To("results", Result.Type),
// belongs to
edge.From("test", Test.Type).Ref("scales"),
}
}
func (Scale) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.Time{},
}
}
// TRANSLATIONS //
// ScaleTranslation holds the schema definition for the ScaleTranslation entity.
type ScaleTranslation struct {
ent.Schema
}
// Fields of the ScaleTranslation.
func (ScaleTranslation) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).Default(uuid.New),
field.String("title").NotEmpty(),
field.String("description").Optional(),
field.String("abbreviation").NotEmpty().MaxLen(24).Default("SCALE"),
}
}
// Edges of the ScaleTranslation.
func (ScaleTranslation) Edges() []ent.Edge {
return []ent.Edge{
// belongs to
edge.From("scale", Scale.Type).Ref("translations").Unique(),
}
}
func (ScaleTranslation) Indexes() []ent.Index {
return []ent.Index{
// one translation per locale per scale
index.Edges("scale").Fields("locale").Unique(),
}
}
func (ScaleTranslation) Mixin() []ent.Mixin {
return []ent.Mixin{
LocaleMixin{}, // holds locale names
}
}