/
asset.go
62 lines (56 loc) · 1.42 KB
/
asset.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
package schema
import (
"entgo.io/contrib/entgql"
"entgo.io/ent"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"github.com/chenningg/hermitboard-api/ent/schema/mixin"
)
// Asset holds the schema definition for the Asset entity.
type Asset struct {
ent.Schema
}
// Adds id, created_at and updated_at fields.
func (Asset) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.PULIDMixinWithPrefix("AST"),
mixin.CreatedAtMixin{},
mixin.UpdatedAtMixin{},
mixin.DeletedAtMixin{},
}
}
// Fields of the Asset.
func (Asset) Fields() []ent.Field {
return nil
}
// Edges of the Asset.
func (Asset) Edges() []ent.Edge {
return []ent.Edge{
edge.To("asset_class", AssetClass.Type).
Unique().
Required().
StructTag("json:\"assetClass,omitempty\"").
Annotations(
entgql.MapsTo("assetClass"),
),
edge.To("cryptocurrency", Cryptocurrency.Type).
Unique().
Annotations(
entgql.MapsTo("cryptocurrency"),
entgql.Skip(entgql.SkipMutationUpdateInput),
),
edge.To("daily_asset_prices", DailyAssetPrice.Type).
StructTag("json:\"dailyAssetPrices,omitempty\"").
Annotations(
entgql.RelayConnection(), entgql.MapsTo("dailyAssetPrices"),
entgql.Skip(entgql.SkipWhereInput|entgql.SkipMutationUpdateInput),
),
}
}
func (Asset) Annotations() []schema.Annotation {
return []schema.Annotation{
entgql.RelayConnection(),
entgql.QueryField("assets"),
entgql.Mutations(entgql.MutationUpdate()),
}
}