Feat: add models/cache/config
This commit is contained in:
		
							
								
								
									
										25
									
								
								models/auth.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								models/auth.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| package models | ||||
|  | ||||
| import ( | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| // each session contains the username of the user and the time at which it expires | ||||
| type Session struct { | ||||
| 	Username    string | ||||
| 	CurrentRoom string | ||||
| 	Expiry      time.Time | ||||
| } | ||||
|  | ||||
| // we'll use this method later to determine if the session has expired | ||||
| func (s Session) IsExpired() bool { | ||||
| 	return s.Expiry.Before(time.Now()) | ||||
| } | ||||
|  | ||||
| func ListUsernames(ss map[string]*Session) []string { | ||||
| 	resp := make([]string, 0, len(ss)) | ||||
| 	for _, s := range ss { | ||||
| 		resp = append(resp, s.Username) | ||||
| 	} | ||||
| 	return resp | ||||
| } | ||||
							
								
								
									
										69
									
								
								models/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								models/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| package models | ||||
|  | ||||
| import "time" | ||||
|  | ||||
| type WordColor string | ||||
|  | ||||
| const ( | ||||
| 	WordColorWhite = "white" | ||||
| 	WordColorBlue  = "blue" | ||||
| 	WordColorRed   = "red" | ||||
| 	WordColorBlack = "black" | ||||
| ) | ||||
|  | ||||
| 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"` | ||||
| 	RoomLink     string | ||||
| 	CreatorName  string   `json:"creator_name"` | ||||
| 	PlayerList   []string `json:"player_list"` | ||||
| 	RedMime      string | ||||
| 	BlueMime     string | ||||
| 	RedGuessers  []string | ||||
| 	BlueGuessers []string | ||||
| 	Cards        []WordCard | ||||
| 	GameSettings *GameSettings `json:"settings"` | ||||
| 	Result       uint8         // 0 for unknown; 1 is win for red; 2 if for blue; | ||||
| } | ||||
|  | ||||
| type WordCard struct { | ||||
| 	Word     string | ||||
| 	Color    WordColor | ||||
| 	Revealed bool | ||||
| } | ||||
|  | ||||
| type RoomPublic struct { | ||||
| 	ID           string        `json:"id" db:"id"` | ||||
| 	CreatedAt    time.Time     `json:"created_at" db:"created_at"` | ||||
| 	PlayerList   []string      `json:"player_list"` | ||||
| 	CreatorName  string        `json:"creator_name"` | ||||
| 	GameSettings *GameSettings `json:"settings"` | ||||
| 	RedMime      string | ||||
| 	BlueMime     string | ||||
| 	RedGuessers  []string | ||||
| 	BlueGuessers []string | ||||
| } | ||||
|  | ||||
| func (r Room) ToPublic() RoomPublic { | ||||
| 	return RoomPublic{ | ||||
| 		ID:           r.ID, | ||||
| 		CreatedAt:    r.CreatedAt, | ||||
| 		PlayerList:   r.PlayerList, | ||||
| 		GameSettings: r.GameSettings, | ||||
| 		CreatorName:  r.CreatorName, | ||||
| 		RedMime:      r.RedMime, | ||||
| 		BlueMime:     r.BlueMime, | ||||
| 		RedGuessers:  r.RedGuessers, | ||||
| 		BlueGuessers: r.BlueGuessers, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type GameSettings struct { | ||||
| 	IsRunning   bool   `json:"is_running"` | ||||
| 	Language    string `json:"language" example:"en" form:"language"` | ||||
| 	RoundTime   int32  `json:"round_time"` | ||||
| 	ProgressPct uint32 `json:"progress_pct"` | ||||
| 	IsOver      bool | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder