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.
82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/index"
|
|
)
|
|
|
|
// QuestionAttempt holds the schema definition for the QuestionAttempt entity.
|
|
type QuestionAttempt struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the QuestionAttempt.
|
|
func (QuestionAttempt) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.String("id").
|
|
Unique().
|
|
Immutable(),
|
|
field.String("session_id").
|
|
NotEmpty().
|
|
Comment("ID of the game session this attempt belongs to"),
|
|
field.String("question_id").
|
|
NotEmpty().
|
|
Comment("ID of the question being attempted"),
|
|
field.Int("attempt_number").
|
|
Positive().
|
|
Comment("Which attempt this is (1, 2, or 3)"),
|
|
field.String("submitted_answer").
|
|
NotEmpty().
|
|
Comment("The answer submitted by the player"),
|
|
field.Bool("is_correct").
|
|
Comment("Whether the submitted answer was correct"),
|
|
field.Bool("used_hint").
|
|
Default(false).
|
|
Comment("Whether a hint was used for this attempt"),
|
|
field.Int("points_awarded").
|
|
Default(0).
|
|
NonNegative().
|
|
Comment("Points awarded for this attempt"),
|
|
field.Time("submitted_at").
|
|
Default(time.Now).
|
|
Immutable().
|
|
Comment("When this attempt was submitted"),
|
|
field.Int64("time_taken_ms").
|
|
NonNegative().
|
|
Comment("Time taken for this attempt in milliseconds"),
|
|
field.JSON("metadata", map[string]interface{}{}).
|
|
Optional().
|
|
Comment("Additional metadata as JSON"),
|
|
}
|
|
}
|
|
|
|
// Edges of the QuestionAttempt.
|
|
func (QuestionAttempt) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("session", GameSession.Type).
|
|
Ref("attempts").
|
|
Unique().
|
|
Required().
|
|
Field("session_id"),
|
|
edge.To("question", Question.Type).
|
|
Unique().
|
|
Required().
|
|
Field("question_id"),
|
|
}
|
|
}
|
|
|
|
// Indexes of the QuestionAttempt.
|
|
func (QuestionAttempt) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("session_id"),
|
|
index.Fields("question_id"),
|
|
index.Fields("submitted_at"),
|
|
index.Fields("is_correct"),
|
|
index.Fields("session_id", "question_id"),
|
|
index.Fields("session_id", "attempt_number"),
|
|
}
|
|
} |