2023-10-27 09:51:58 +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"),
|
2023-10-28 23:12:07 +00:00
|
|
|
field.Text("summary").Optional().Nillable(),
|
|
|
|
field.Text("description").Optional().Nillable(),
|
2023-10-27 09:51:58 +00:00
|
|
|
field.Float("price").Default(0).Positive(),
|
|
|
|
field.Float("original_price").Default(0).Positive(),
|
|
|
|
field.Int("quantity").Default(0).Positive(),
|
|
|
|
field.Bool("status").Default(true),
|
2023-10-28 23:12:07 +00:00
|
|
|
field.Int("product_category_id").Optional().Nillable(),
|
|
|
|
field.Int("business_id").Optional().Nillable(),
|
|
|
|
field.Int("user_id").Optional().Nillable(),
|
2023-10-27 09:51:58 +00:00
|
|
|
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{
|
2023-10-28 23:12:07 +00:00
|
|
|
edge.From("product_categories", ProductCategory.Type).Ref("products").Unique().Field("product_category_id"),
|
|
|
|
edge.From("businesses", Business.Type).Ref("products").Unique().Field("business_id"),
|
|
|
|
edge.From("users", User.Type).Ref("products").Unique().Field("user_id"),
|
2023-10-27 09:51:58 +00:00
|
|
|
}
|
|
|
|
}
|