Draft: feat login

This commit is contained in:
2025-09-05 03:59:25 +08:00
parent 6d7074198f
commit ca49efac87
43 changed files with 2023 additions and 91 deletions

47
models/room.go Normal file
View File

@@ -0,0 +1,47 @@
package models
import (
"fmt"
"github.com/uptrace/bun"
)
type RoomType int
const (
RoomTypeWordle RoomType = iota
)
var (
RoomTypeStr = []string{"Wordle"}
)
type RoomStatus int
const (
RoomStatusWaiting RoomStatus = iota
RoomStatusPlaying
RoomStatusEnded
)
var (
RoomStatusStr = []string{"Waiting", "Playing", "Ended"}
)
type Room struct {
bun.BaseModel `bun:"table:room"`
Id int `bun:"id,pk,autoincrement"`
Creater string `bun:"creater"`
Type RoomType `bun:"type"`
Status RoomStatus `bun:"status"`
}
func (self Room) View() string {
return fmt.Sprintf("%2d. %10s %10s [%s]",
self.Id,
self.Creater,
RoomTypeStr[self.Type],
RoomStatusStr[self.Status],
)
}

39
models/user.go Normal file
View File

@@ -0,0 +1,39 @@
package models
import (
"fmt"
"github.com/uptrace/bun"
)
type User struct {
bun.BaseModel `bun:"table:user" json:"-"`
Username string `bun:"username,pk"`
Password string `bun:"password"`
}
type UserState int
const (
UserStateIdle UserState = iota
UserStateGaming
)
var (
UserStateStr = []string{"Idle", "Gaming"}
)
type UserStatus struct {
bun.BaseModel `bun:"table:user_status"`
Username string `bun:"username,pk" json:"username"`
State UserState `bun:"state" json:"state"`
}
func (self UserStatus) View() string {
return fmt.Sprintf("%s [%s]",
self.Username,
UserStateStr[self.State],
)
}