Use UUIDs for AskedQuestions as well

This commit is contained in:
Vojtěch Káně
2021-02-15 13:21:38 +01:00
parent e677014d75
commit e4ab598b49
2 changed files with 3 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import (
"github.com/facebook/ent"
"github.com/facebook/ent/schema/edge"
"github.com/facebook/ent/schema/field"
"github.com/google/uuid"
)
type AskedQuestion struct {
@@ -12,6 +13,7 @@ type AskedQuestion struct {
func (AskedQuestion) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.New()).Immutable(),
field.Time("asked").Immutable(),
field.Time("ended"),
}

View File

@@ -205,7 +205,7 @@ func (m *Model) NextQuestion(sessionId uuid.UUID, c context.Context) error {
}
if next, err := query.First(c); err == nil {
if _, err := tx.AskedQuestion.Create().SetAsked(now).SetSessionID(sessionId).SetQuestion(next).SetEnded(now.Add(time.Duration(int64(next.DefaultLength)) * time.Millisecond)).Save(c); err != nil {
if _, err := tx.AskedQuestion.Create().SetID(uuid.New()).SetAsked(now).SetSessionID(sessionId).SetQuestion(next).SetEnded(now.Add(time.Duration(int64(next.DefaultLength)) * time.Millisecond)).Save(c); err != nil {
return err
}
} else if ent.IsNotFound(err) {