mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-25 08:16:32 +00:00
c4b923847a
* basic currency service for loading at runtime * api endpoint for currencies * sort slice before return * remove currency validation * validate using currency service * implement selecting dynamic currency options * bump go version * fix type definition * specify explicit type * change go versions * proper types for assetId * log/return currency error * make case insensative * use ToUpper instead * feat: adding new currencies (#715) * fix: task swag (#710) Co-authored-by: Quoing <pavel.cadersky@mavenir.com> * [feat] Adding new currencies --------- Co-authored-by: quoing <quoing@users.noreply.github.com> Co-authored-by: Quoing <pavel.cadersky@mavenir.com> Co-authored-by: Bradley <41597815+userbradley@users.noreply.github.com> * remove ts file and consoldate new values into json * move flag to options namespace * add env config for currencies * basic documentaion * remove in sync test --------- Co-authored-by: quoing <quoing@users.noreply.github.com> Co-authored-by: Quoing <pavel.cadersky@mavenir.com> Co-authored-by: Bradley <41597815+userbradley@users.noreply.github.com>
94 lines
1.7 KiB
Go
94 lines
1.7 KiB
Go
package schema
|
|
|
|
import (
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/mixin"
|
|
"github.com/google/uuid"
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
|
)
|
|
|
|
// User holds the schema definition for the User entity.
|
|
type User struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (User) Mixin() []ent.Mixin {
|
|
return []ent.Mixin{
|
|
mixins.BaseMixin{},
|
|
GroupMixin{ref: "users"},
|
|
}
|
|
}
|
|
|
|
// Fields of the User.
|
|
func (User) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.String("name").
|
|
MaxLen(255).
|
|
NotEmpty(),
|
|
field.String("email").
|
|
MaxLen(255).
|
|
NotEmpty().
|
|
Unique(),
|
|
field.String("password").
|
|
MaxLen(255).
|
|
NotEmpty().
|
|
Sensitive(),
|
|
field.Bool("is_superuser").
|
|
Default(false),
|
|
field.Bool("superuser").
|
|
Default(false),
|
|
field.Enum("role").
|
|
Default("user").
|
|
Values("user", "owner"),
|
|
field.Time("activated_on").
|
|
Optional(),
|
|
}
|
|
}
|
|
|
|
// Edges of the User.
|
|
func (User) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.To("auth_tokens", AuthTokens.Type).
|
|
Annotations(entsql.Annotation{
|
|
OnDelete: entsql.Cascade,
|
|
}),
|
|
edge.To("notifiers", Notifier.Type).
|
|
Annotations(entsql.Annotation{
|
|
OnDelete: entsql.Cascade,
|
|
}),
|
|
}
|
|
}
|
|
|
|
// UserMixin when embedded in an ent.Schema, adds a reference to
|
|
// the Group entity.
|
|
type UserMixin struct {
|
|
ref string
|
|
field string
|
|
mixin.Schema
|
|
}
|
|
|
|
func (g UserMixin) Fields() []ent.Field {
|
|
if g.field != "" {
|
|
return []ent.Field{
|
|
field.UUID(g.field, uuid.UUID{}),
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (g UserMixin) Edges() []ent.Edge {
|
|
edge := edge.From("user", User.Type).
|
|
Ref(g.ref).
|
|
Unique().
|
|
Required()
|
|
|
|
if g.field != "" {
|
|
edge = edge.Field(g.field)
|
|
}
|
|
|
|
return []ent.Edge{edge}
|
|
}
|