adding validated services? patching forcad_local.py
This commit is contained in:
54
OmCTF-2025/services/block_game/backend/schema/level.go
Normal file
54
OmCTF-2025/services/block_game/backend/schema/level.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"omctf.ru/block-game-backend/utils/xy"
|
||||
)
|
||||
|
||||
// Level holds the schema definition for the Level entity.
|
||||
type Level struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// JSON data
|
||||
type LevelData struct {
|
||||
Size int `json:"size"`
|
||||
Tiles []Tile `json:"tiles"`
|
||||
}
|
||||
|
||||
type Tile struct {
|
||||
Kind string `json:"kind"`
|
||||
Pos xy.Point `json:"pos"`
|
||||
Data json.RawMessage `json:"data"`
|
||||
}
|
||||
|
||||
// Fields of the Level.
|
||||
func (Level) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").Unique().Match(regexp.MustCompile(`^\w{1,64}$`)),
|
||||
field.String("description"),
|
||||
field.Enum("visibility").Values("private", "public"),
|
||||
field.JSON("data", LevelData{}),
|
||||
field.String("prize"), // only for players who passed the level!!!
|
||||
field.Time("createdAt").Default(func() (t time.Time) {
|
||||
return time.Now().UTC()
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Level.
|
||||
func (Level) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", User.Type).
|
||||
Ref("ownedLevels").
|
||||
Unique(),
|
||||
edge.From("invitedPlayers", User.Type).
|
||||
Ref("invitedToLevels"),
|
||||
}
|
||||
}
|
||||
27
OmCTF-2025/services/block_game/backend/schema/setting.go
Normal file
27
OmCTF-2025/services/block_game/backend/schema/setting.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Setting holds the schema definition for the Setting entity.
|
||||
type Setting struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Setting.
|
||||
func (Setting) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("key").
|
||||
Unique().
|
||||
NotEmpty(),
|
||||
field.String("value").
|
||||
NotEmpty(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Setting.
|
||||
func (Setting) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
34
OmCTF-2025/services/block_game/backend/schema/user.go
Normal file
34
OmCTF-2025/services/block_game/backend/schema/user.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// User holds the schema definition for the User entity.
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("username").
|
||||
Unique().
|
||||
Match(regexp.MustCompile(`^\w{1,64}$`)),
|
||||
field.String("password").
|
||||
MaxLen(128).
|
||||
NotEmpty(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("ownedLevels", Level.Type),
|
||||
edge.To("invitedToLevels", Level.Type),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user