70 lines
2.0 KiB
Go
70 lines
2.0 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
var shopDefaultRating = decimal.RequireFromString("5.00")
|
|
|
|
// Shops holds the schema definition for the Shops entity.
|
|
type Shops struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Annotations of the Shops.
|
|
func (Shops) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{
|
|
entsql.Annotation{
|
|
Table: "shops",
|
|
Checks: map[string]string{
|
|
"chk_commission_type": "commission_type IN ('fixed', 'percentage')",
|
|
"chk_dispatch_mode": "dispatch_mode IN ('manual', 'auto')",
|
|
"chk_rating_range": "rating >= 0 AND rating <= 5",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
// Fields of the Shops.
|
|
func (Shops) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int64("id").Immutable().Unique(),
|
|
field.Int64("owner_id").Unique(),
|
|
field.String("name").MaxLen(200),
|
|
field.String("banner").Optional().Nillable(),
|
|
field.String("description").Optional().Nillable(),
|
|
field.Other("rating", decimal.Decimal{}).
|
|
Optional().
|
|
Default(shopDefaultRating).
|
|
SchemaType(map[string]string{
|
|
dialect.Postgres: "decimal(3,2)",
|
|
}),
|
|
field.Int("total_orders").Optional().Default(0),
|
|
field.Int("player_count").Optional().Default(0),
|
|
field.String("commission_type").MaxLen(20).Default("percentage"),
|
|
field.Other("commission_value", decimal.Decimal{}).
|
|
SchemaType(map[string]string{
|
|
dialect.Postgres: "decimal(10,2)",
|
|
}),
|
|
field.Bool("allow_multi_shop").Optional().Default(false),
|
|
field.Bool("allow_independent_orders").Optional().Default(true),
|
|
field.String("dispatch_mode").MaxLen(20).Default("manual"),
|
|
field.Strings("announcements").Optional().Default([]string{}),
|
|
field.JSON("template_config", map[string]any{}).Optional(),
|
|
field.Time("created_at").Default(time.Now).Immutable(),
|
|
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
|
|
}
|
|
}
|
|
|
|
// Edges of the Shops.
|
|
func (Shops) Edges() []ent.Edge {
|
|
return nil
|
|
}
|