Enha: state to hold room_id instead of whole room
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
type WordColor string
|
||||
|
||||
@ -28,10 +32,10 @@ func StrToWordColor(s string) WordColor {
|
||||
}
|
||||
|
||||
type Room struct {
|
||||
ID string `json:"id" db:"id"`
|
||||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||||
RoomName string `json:"room_name"`
|
||||
RoomPass string `json:"room_pass"`
|
||||
ID string `json:"id" db:"id"`
|
||||
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
||||
// RoomName string `json:"room_name"`
|
||||
RoomPass string `json:"room_pass"`
|
||||
RoomLink string
|
||||
CreatorName string `json:"creator_name"`
|
||||
PlayerList []string `json:"player_list"`
|
||||
@ -70,3 +74,22 @@ type RoomReq struct {
|
||||
RoomName string `json:"room_name" form:"room_name"`
|
||||
// GameSettings
|
||||
}
|
||||
|
||||
func (rr *RoomReq) CreateRoom(creator string) *Room {
|
||||
roomID := xid.New().String()
|
||||
return &Room{
|
||||
// RoomName: ,
|
||||
RoomPass: rr.RoomPass,
|
||||
ID: roomID,
|
||||
CreatedAt: time.Now(),
|
||||
PlayerList: []string{creator},
|
||||
CreatorName: creator,
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
|
||||
type FullInfo struct {
|
||||
State *UserState
|
||||
Room *Room
|
||||
}
|
||||
|
@ -42,12 +42,12 @@ func StrToUserRole(s string) UserRole {
|
||||
|
||||
type UserState struct {
|
||||
Username string
|
||||
Room Room
|
||||
RoomID string
|
||||
Team UserTeam
|
||||
Role UserRole
|
||||
}
|
||||
|
||||
func MakeTestState() *UserState {
|
||||
func MakeTestState() *FullInfo {
|
||||
cards := []WordCard{
|
||||
{Word: "hamster", Color: "blue"},
|
||||
{Word: "child", Color: "red"},
|
||||
@ -75,17 +75,21 @@ func MakeTestState() *UserState {
|
||||
{Word: "tomato", Color: "red"},
|
||||
{Word: "cloud", Color: "white"},
|
||||
}
|
||||
room := Room{
|
||||
room := &Room{
|
||||
ID: "test-id",
|
||||
CreatedAt: time.Now(),
|
||||
CreatorName: "test-name",
|
||||
Cards: cards,
|
||||
}
|
||||
return &UserState{
|
||||
us := &UserState{
|
||||
Username: "test-name",
|
||||
Team: UserTeamNone,
|
||||
Role: UserRoleNone,
|
||||
Room: room,
|
||||
RoomID: "test-id",
|
||||
}
|
||||
return &FullInfo{
|
||||
State: us,
|
||||
Room: room,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user