Initial commit
This commit is contained in:
43
pkg/model/ent/schema/answer.go
Normal file
43
pkg/model/ent/schema/answer.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/schema/edge"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Answer struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Answer) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.New()).Immutable().Unique(),
|
||||
field.Time("answered").Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Answer) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
}
|
||||
}
|
||||
|
||||
func (Answer) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("choice", Choice.Type).
|
||||
Ref("answers").
|
||||
Unique().
|
||||
Required(),
|
||||
edge.From("answerer", Player.Type).
|
||||
Ref("answers").
|
||||
Unique().
|
||||
Required(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Answer) Config() ent.Config {
|
||||
return ent.Config{
|
||||
Table: "answers",
|
||||
}
|
||||
}
|
||||
41
pkg/model/ent/schema/choice.go
Normal file
41
pkg/model/ent/schema/choice.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/schema/edge"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Choice struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Choice) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.New()).Immutable(),
|
||||
field.Text("title").MinLen(1).MaxLen(256),
|
||||
field.Bool("correct"),
|
||||
}
|
||||
}
|
||||
|
||||
func (Choice) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
}
|
||||
}
|
||||
|
||||
func (Choice) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("question", Question.Type).
|
||||
Ref("choices").
|
||||
Unique().
|
||||
Required(),
|
||||
edge.To("answers", Answer.Type),
|
||||
}
|
||||
}
|
||||
|
||||
func (Choice) Config() ent.Config {
|
||||
return ent.Config{
|
||||
Table: "options",
|
||||
}
|
||||
}
|
||||
34
pkg/model/ent/schema/game.go
Normal file
34
pkg/model/ent/schema/game.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/schema/edge"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Game struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Game) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.New()).Unique().Immutable(),
|
||||
field.Text("name").MaxLen(64),
|
||||
field.Time("created").Immutable(),
|
||||
field.Text("author").MaxLen(64),
|
||||
}
|
||||
}
|
||||
|
||||
func (Game) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("sessions", Session.Type),
|
||||
edge.To("questions", Question.Type),
|
||||
}
|
||||
}
|
||||
|
||||
func (Game) Config() ent.Config {
|
||||
return ent.Config{
|
||||
Table: "games",
|
||||
}
|
||||
}
|
||||
45
pkg/model/ent/schema/player.go
Normal file
45
pkg/model/ent/schema/player.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/schema/edge"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/facebook/ent/schema/index"
|
||||
"github.com/google/uuid"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Player) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.New()).Immutable(),
|
||||
field.Text("name").MaxLen(64).MinLen(1).Match(regexp.MustCompile("(?:[a-z]|[A-Z]|_|-|.|,|[0-9])+")),
|
||||
field.Time("joined").Immutable(),
|
||||
field.Bool("organiser").Default(false),
|
||||
}
|
||||
}
|
||||
|
||||
func (Player) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("name").Edges("session").Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Player) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("session", Session.Type).
|
||||
Ref("players").
|
||||
Unique().
|
||||
Required(),
|
||||
edge.To("answers", Answer.Type),
|
||||
}
|
||||
}
|
||||
|
||||
func (Player) Config() ent.Config {
|
||||
return ent.Config{
|
||||
Table: "players",
|
||||
}
|
||||
}
|
||||
44
pkg/model/ent/schema/question.go
Normal file
44
pkg/model/ent/schema/question.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/schema/edge"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/facebook/ent/schema/index"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Question struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Question) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.New()).Immutable(),
|
||||
field.Text("title").MaxLen(256).MinLen(1),
|
||||
field.Int("order"),
|
||||
}
|
||||
}
|
||||
|
||||
func (Question) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("order").Edges("game").Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Question) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("game", Game.Type).
|
||||
Ref("questions").
|
||||
Unique().
|
||||
Required(),
|
||||
edge.To("choices", Choice.Type),
|
||||
edge.To("current_sessions", Session.Type),
|
||||
}
|
||||
}
|
||||
|
||||
func (Question) Config() ent.Config {
|
||||
return ent.Config{
|
||||
Table: "questions",
|
||||
}
|
||||
}
|
||||
46
pkg/model/ent/schema/session.go
Normal file
46
pkg/model/ent/schema/session.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"github.com/facebook/ent"
|
||||
"github.com/facebook/ent/schema/edge"
|
||||
"github.com/facebook/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Session) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.New()).Immutable(),
|
||||
field.Time("created").Immutable(),
|
||||
field.Time("started").Nillable().Optional(), // TODO remove?
|
||||
field.Time("current_question_until").Nillable().Optional(),
|
||||
field.String("code").MinLen(6).MaxLen(6).Immutable().Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Session) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
}
|
||||
}
|
||||
|
||||
func (Session) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("game", Game.Type).
|
||||
Ref("sessions").
|
||||
Unique().
|
||||
Required(),
|
||||
edge.To("players", Player.Type),
|
||||
edge.From("current_question", Question.Type).
|
||||
Ref("current_sessions").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Session) Config() ent.Config {
|
||||
return ent.Config{
|
||||
Table: "sessions",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user