homebox/backend/internal/data/ent/schema/group.go
Hayden c4b923847a
feat: user defined currencies (#700)
* 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>
2024-01-18 10:45:42 -09:00

85 lines
1.6 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"
)
// 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.String("currency").
Default("usd"),
}
}
// Edges of the Home.
func (Group) Edges() []ent.Edge {
owned := func(name string, t any) ent.Edge {
return edge.To(name, t).
Annotations(entsql.Annotation{
OnDelete: entsql.Cascade,
})
}
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
}
}
// 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}
}