Feat: login done
This commit is contained in:
47
models/room.go
Normal file
47
models/room.go
Normal 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
39
models/user.go
Normal 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],
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user