Fill Session.Started

This commit is contained in:
Vojtěch Káně
2021-03-24 19:30:00 +01:00
parent e2e7130e40
commit 782f96ebbd
2 changed files with 5 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ func (Session) Fields() []ent.Field {
return []ent.Field{ return []ent.Field{
field.UUID("id", uuid.Nil).Immutable(), field.UUID("id", uuid.Nil).Immutable(),
field.Time("created").Immutable(), field.Time("created").Immutable(),
field.Time("started").Nillable().Optional(), // TODO remove? field.Time("started").Nillable().Optional(),
field.String("code").MinLen(6).MaxLen(6).Immutable().Unique(), field.String("code").MinLen(6).MaxLen(6).Immutable().Unique(),
} }
} }

View File

@@ -188,6 +188,10 @@ func (m *Model) NextQuestion(sessionId uuid.UUID, now time.Time, c context.Conte
// TODO rollback only if not yet committed // TODO rollback only if not yet committed
defer tx.Rollback() defer tx.Rollback()
if err := tx.Session.Update().Where(session.ID(sessionId)).Where(session.StartedIsNil()).SetStarted(now).Exec(c); err != nil {
return err
}
var query = tx.Question.Query().Where(question.HasGameWith(game.HasSessionsWith(session.ID(sessionId)))).Order(ent.Asc(question.FieldOrder)) var query = tx.Question.Query().Where(question.HasGameWith(game.HasSessionsWith(session.ID(sessionId)))).Order(ent.Asc(question.FieldOrder))
if current, err := tx.AskedQuestion.Query().Where(askedquestion.HasSessionWith(session.ID(sessionId))).WithQuestion().Order(ent.Desc(askedquestion.FieldAsked)).First(c); err == nil { if current, err := tx.AskedQuestion.Query().Where(askedquestion.HasSessionWith(session.ID(sessionId))).WithQuestion().Order(ent.Desc(askedquestion.FieldAsked)).First(c); err == nil {