You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/index"
|
|
)
|
|
|
|
// Question holds the schema definition for the Question entity.
|
|
type Question struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the Question.
|
|
func (Question) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.String("id").
|
|
Unique().
|
|
Immutable(),
|
|
field.String("theme").
|
|
NotEmpty().
|
|
Comment("The theme category of the question"),
|
|
field.Text("text").
|
|
NotEmpty().
|
|
Comment("The actual question text"),
|
|
field.String("answer").
|
|
NotEmpty().
|
|
Comment("The correct answer to the question"),
|
|
field.Text("hint").
|
|
Optional().
|
|
Comment("Optional hint for the question"),
|
|
field.Enum("difficulty").
|
|
Values("easy", "medium", "hard").
|
|
Default("medium").
|
|
Comment("Difficulty level of the question"),
|
|
field.Bool("is_active").
|
|
Default(true).
|
|
Comment("Whether this question is currently active"),
|
|
field.Time("created_at").
|
|
Default(time.Now).
|
|
Immutable().
|
|
Comment("When the question was created"),
|
|
field.Time("updated_at").
|
|
Default(time.Now).
|
|
UpdateDefault(time.Now).
|
|
Comment("When the question was last updated"),
|
|
}
|
|
}
|
|
|
|
// Edges of the Question.
|
|
func (Question) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.To("attempts", QuestionAttempt.Type),
|
|
edge.From("current_sessions", GameSession.Type).
|
|
Ref("current_question"),
|
|
}
|
|
}
|
|
|
|
// Indexes of the Question.
|
|
func (Question) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("theme"),
|
|
index.Fields("difficulty"),
|
|
index.Fields("is_active"),
|
|
index.Fields("created_at"),
|
|
index.Fields("theme", "difficulty", "is_active"),
|
|
}
|
|
} |