Files
juwan-backend/app/order/rpc/internal/models/schema/orders.go
T

61 lines
1.8 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"
)
// Orders holds the schema definition for the Orders entity.
type Orders struct {
ent.Schema
}
// Annotations of the Orders.
func (Orders) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{
Table: "orders",
Checks: map[string]string{
"chk_order_status": "status IN ('pending_payment', 'pending_accept', 'in_progress', 'pending_close', 'pending_review', 'disputed', 'completed', 'cancelled')",
"chk_price_positive": "total_price > 0",
},
},
}
}
// Fields of the Orders.
func (Orders) Fields() []ent.Field {
return []ent.Field{
field.Int64("id").Immutable().Unique(),
field.Int64("consumer_id"),
field.Int64("player_id"),
field.Int64("shop_id").Optional().Nillable(),
field.JSON("service_snapshot", map[string]any{}).
SchemaType(map[string]string{dialect.Postgres: "jsonb"}),
field.String("status").Default("pending_payment").MaxLen(30),
field.Other("total_price", decimal.Decimal{}).
SchemaType(map[string]string{dialect.Postgres: "decimal(10,2)"}),
field.String("note").Optional().Nillable(),
field.Int("version").Default(1),
field.String("timeout_job_id").Optional().Nillable().MaxLen(100),
field.String("search_text").Optional().Nillable(),
field.Time("created_at").Default(time.Now).Immutable(),
field.Time("accepted_at").Optional().Nillable(),
field.Time("closed_at").Optional().Nillable(),
field.Time("completed_at").Optional().Nillable(),
field.Time("cancelled_at").Optional().Nillable(),
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
}
}
// Edges of the Orders.
func (Orders) Edges() []ent.Edge {
return nil
}