Enha: state to hold room_id instead of whole room

This commit is contained in:
Grail Finder
2025-05-08 10:25:38 +03:00
parent 3ade7310a7
commit b20f7ac6b7
12 changed files with 110 additions and 35 deletions

View File

@ -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
}

View File

@ -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,
}
}