2022-08-30 18:04:50 +00:00
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
|
|
|
"entgo.io/ent"
|
2022-09-04 02:42:03 +00:00
|
|
|
"entgo.io/ent/dialect/entsql"
|
2022-08-30 18:04:50 +00:00
|
|
|
"entgo.io/ent/schema/edge"
|
|
|
|
"entgo.io/ent/schema/field"
|
2023-03-07 06:18:58 +00:00
|
|
|
"entgo.io/ent/schema/mixin"
|
|
|
|
"github.com/google/uuid"
|
2022-10-30 04:05:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
2022-08-30 18:04:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Group holds the schema definition for the Group entity.
|
|
|
|
type Group struct {
|
|
|
|
ent.Schema
|
|
|
|
}
|
|
|
|
|
|
|
|
func (Group) Mixin() []ent.Mixin {
|
|
|
|
return []ent.Mixin{
|
|
|
|
mixins.BaseMixin{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fields of the Home.
|
|
|
|
func (Group) Fields() []ent.Field {
|
|
|
|
return []ent.Field{
|
|
|
|
field.String("name").
|
|
|
|
MaxLen(255).
|
|
|
|
NotEmpty(),
|
|
|
|
field.Enum("currency").
|
|
|
|
Default("usd").
|
2023-07-31 13:59:36 +00:00
|
|
|
Values(
|
|
|
|
"aed",
|
|
|
|
"aud",
|
|
|
|
"bgn",
|
|
|
|
"brl",
|
|
|
|
"cad",
|
|
|
|
"chf",
|
|
|
|
"czk",
|
|
|
|
"dkk",
|
|
|
|
"eur",
|
|
|
|
"gbp",
|
|
|
|
"hkd",
|
|
|
|
"idr",
|
|
|
|
"inr",
|
|
|
|
"jpy",
|
|
|
|
"krw",
|
|
|
|
"mxn",
|
|
|
|
"nok",
|
|
|
|
"nzd",
|
|
|
|
"pln",
|
|
|
|
"rmb",
|
|
|
|
"ron",
|
|
|
|
"rub",
|
|
|
|
"sar",
|
|
|
|
"sek",
|
|
|
|
"sgd",
|
|
|
|
"thb",
|
|
|
|
"try",
|
|
|
|
"usd",
|
2023-08-23 17:29:22 +00:00
|
|
|
"xag",
|
|
|
|
"xau",
|
2023-07-31 13:59:36 +00:00
|
|
|
"zar",
|
|
|
|
),
|
2022-08-30 18:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edges of the Home.
|
|
|
|
func (Group) Edges() []ent.Edge {
|
2023-03-07 06:18:58 +00:00
|
|
|
owned := func(name string, t any) ent.Edge {
|
|
|
|
return edge.To(name, t).
|
2022-09-12 22:47:27 +00:00
|
|
|
Annotations(entsql.Annotation{
|
|
|
|
OnDelete: entsql.Cascade,
|
2023-03-07 06:18:58 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return []ent.Edge{
|
|
|
|
owned("users", User.Type),
|
|
|
|
owned("locations", Location.Type),
|
|
|
|
owned("items", Item.Type),
|
|
|
|
owned("labels", Label.Type),
|
|
|
|
owned("documents", Document.Type),
|
|
|
|
owned("invitation_tokens", GroupInvitationToken.Type),
|
|
|
|
owned("notifiers", Notifier.Type),
|
|
|
|
// $scaffold_edge
|
2022-08-30 18:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-07 06:18:58 +00:00
|
|
|
|
|
|
|
// GroupMixin when embedded in an ent.Schema, adds a reference to
|
|
|
|
// the Group entity.
|
|
|
|
type GroupMixin struct {
|
|
|
|
ref string
|
|
|
|
field string
|
|
|
|
mixin.Schema
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g GroupMixin) Fields() []ent.Field {
|
|
|
|
if g.field != "" {
|
|
|
|
return []ent.Field{
|
|
|
|
field.UUID(g.field, uuid.UUID{}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g GroupMixin) Edges() []ent.Edge {
|
|
|
|
edge := edge.From("group", Group.Type).
|
|
|
|
Ref(g.ref).
|
|
|
|
Unique().
|
|
|
|
Required()
|
|
|
|
|
|
|
|
if g.field != "" {
|
|
|
|
edge = edge.Field(g.field)
|
|
|
|
}
|
|
|
|
|
|
|
|
return []ent.Edge{edge}
|
|
|
|
}
|