telegram-commerce/ent/schema/product.go

35 lines
858 B
Go
Raw Normal View History

2023-10-25 21:54:32 +00:00
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"time"
)
// Product holds the schema definition for the Product entity.
type Product struct {
ent.Schema
}
// Fields of the Product.
func (Product) Fields() []ent.Field {
return []ent.Field{
field.String("name").Default("unknown"),
field.String("description").Optional().Nillable(),
field.Float("price").Default(0).Positive(),
field.Float("original_price").Default(0).Positive(),
field.Int("quantity").Default(0).Positive(),
field.Bool("status").Default(true),
field.Time("created_at").Default(time.Now()),
field.Time("updated_at").Default(time.Now()).UpdateDefault(time.Now),
}
}
// Edges of the Product.
func (Product) Edges() []ent.Edge {
return []ent.Edge{
edge.From("productCategory", ProductCategory.Type).Ref("products"),
}
}