Documentation
¶
Index ¶
- Constants
- Variables
- func GetRank(userID int64) int64
- func GetUserIDByUser(user *User) int64
- func GetUserQuestionsLen() (int64, error)
- func IsUser(userID int64) (bool, error)
- func JoinLobby(code string, userID int64) error
- func JoinOrCreateLobby(choice, code string, userID int64) error
- func MigrateQuestions(client *redis.Client, path string) error
- func NewQuestion(statement, answer string, choices []string) error
- func NewRedisDB() error
- func PostUpdate(userID int64, body string) error
- func RegisterUser(username, password string) error
- func UpdateRank(userID, points int64) error
- func UserConfirmAnswer(userID int64, choice string) (bool, error)
- type Lobby
- func (l *Lobby) AddMember(userID int64) error
- func (l *Lobby) CloseLobby() error
- func (l *Lobby) GetCode() (string, error)
- func (l *Lobby) GetHostID() (int64, error)
- func (l *Lobby) GetLobbyID() (int64, error)
- func (l *Lobby) GetMembers() ([]*User, error)
- func (l *Lobby) GetPlayers() ([]string, error)
- func (l *Lobby) GetStatus() (int64, error)
- func (l *Lobby) GetTopMember() (*User, error)
- func (l *Lobby) IsMember(userID int64) (bool, error)
- func (l *Lobby) LeaveLobby(userID int64) error
- func (l *Lobby) SetHostID(hostID int64) error
- func (l *Lobby) SetStatus(status int64) error
- type Question
- type QuestionT
- type RankT
- type Update
- type User
- type UserQuestion
- func (uq *UserQuestion) AddPoints(amount int64) error
- func (uq *UserQuestion) GetPoints() (int64, error)
- func (uq *UserQuestion) GetQuestion() (*Question, error)
- func (uq *UserQuestion) GetUnansweredQuestions() ([]*Question, error)
- func (uq *UserQuestion) GetUser() (*User, error)
- func (uq *UserQuestion) GetUserQuestions() ([]*Question, error)
- func (uq *UserQuestion) RegisterQuestion(questionID int64) error
Constants ¶
const ( // StatusWaiting means the status is "waiting" StatusWaiting = 0 // StatusStarting means the status is "starting" StatusStarting = 1 // StatusOngoing means the status is "on-going" StatusOngoing = 2 // StatusEnded means the status is "ended" StatusEnded = 3 )
Variables ¶
var ( // ErrUserNotFound common error on login form when the user is not found ErrUserNotFound = errors.New("user not found") // ErrInvalidLogin common error on login form when the user does not match its login credentials ErrInvalidLogin = errors.New("invalid login") // ErrUsernameTaken common error on registration form when the username already existed ErrUsernameTaken = errors.New("username taken") // ErrQuestionDuplicate specific error on whether the question has already been asked ErrQuestionDuplicate = errors.New("question already existed") // ErrEmptyUserQuestion specific error for capturing uninitialized array error ErrEmptyUserQuestion = errors.New("user has no question") // ErrTypeMismatch specific error for capturing type mismatch ErrTypeMismatch = errors.New("the type didn't match") // ErrNilClient gives error message when redis client variable is nil ErrNilClient = errors.New("client is nil") // ErrUserInLobby gives error message when user attempts to join a lobby when is already in lobby ErrUserInLobby = errors.New("user is currently joined in to a lobby") // ErrUserNotInLobby gives error message when user attempts to get its current lobby when is not in lobby ErrUserNotInLobby = errors.New("user is currently not joined in to a lobby") // ErrLobbyEmptyMembers gives error message when the lobby has no members ErrLobbyEmptyMembers = errors.New("lobby is currently empty") // ErrGameEnded gives error message when the game has already ended ErrGameEnded = errors.New("game has already end") )
Functions ¶
func GetUserIDByUser ¶
GetUserIDByUser gets the user id using the user
func GetUserQuestionsLen ¶
GetUserQuestionsLen Questions len getter
func JoinOrCreateLobby ¶
JoinOrCreateLobby process whether the lobby is joined or created by the current user
func MigrateQuestions ¶
MigrateQuestions sends the questions.json to the redis server
func NewQuestion ¶
NewQuestion creates a new question, saves it to the database, and returns the newly created question
func NewRedisDB ¶
func NewRedisDB() error
NewRedisDB instantiates a package-level redis client access
func RegisterUser ¶
RegisterUser register a valid user
func UpdateRank ¶
UpdateRank replaces the user's points with a new value
Types ¶
type Lobby ¶
type Lobby struct {
// contains filtered or unexported fields
}
Lobby is a manager for accessing users in the database
func GetLobbyByCode ¶
GetLobbyByCode get the lobby based on the given code
func GetLobbyByUserID ¶
func NewLobby ¶
NewLobby creates new lobby, saves it to the database, and returns the newly created lobby
func (*Lobby) CloseLobby ¶
CloseLobby sets the lobby status to ended then permits entering of member
func (*Lobby) GetMembers ¶
GetMembers gets all the members
func (*Lobby) GetPlayers ¶
GetPlayers get all the players' usernames
func (*Lobby) GetTopMember ¶
GetTopMember gets the member supposedly inherits the host role
func (*Lobby) LeaveLobby ¶
LeaveLobby makes the user leave from the lobby
type Question ¶
type Question struct {
// contains filtered or unexported fields
}
Question is a manager for accessing questions in the database
func GetAllQuestions ¶
GetAllQuestions All Updates getter
func GetQuestions ¶
GetQuestions gets all updates related to the user
func (*Question) GetChoices ¶
GetChoices Choices getter
func (*Question) GetQuestionID ¶
GetQuestionID QuestionID getter
func (*Question) GetStatement ¶
GetStatement Statement getter
type QuestionT ¶
type QuestionT struct { Statement string `csv:"statement" json:"statement"` Answer string `csv:"answer" json:"answer"` Choices []string `csv:"choices" json:"choices"` }
QuestionT is a unit for the exam
func GetQuestion ¶
GetQuestion retrieves a whole struct of question from the database
type RankT ¶
RankT is a simple data struct for a sorted leaderboard
func GetCurrentStandings ¶
GetCurrentStandings list the raks of the 12 users above and below your current standing
type Update ¶
type Update struct {
// contains filtered or unexported fields
}
Update is a manager for accessing updates in the database
func GetUpdates ¶
GetUpdates gets all updates related to the user
type User ¶
type User struct {
// contains filtered or unexported fields
}
User is a manager for accessing users in the database
func AuthenticateUser ¶
AuthenticateUser authenticates the user by its username and password
func GetUserByUserID ¶
GetUserByUserID gets user using a user id
func GetUserByUsername ¶
GetUserByUsername gets the user using the username
func NewUser ¶
NewUser create a new user, saves it to the database, and returns the newly created user
func (*User) Authenticate ¶
Authenticate will validates the login attempt
type UserQuestion ¶
type UserQuestion struct {
// contains filtered or unexported fields
}
UserQuestion is a manager for accessing users' current question status in the database
func GetUserQuestion ¶
func GetUserQuestion(userID int64) (*UserQuestion, error)
GetUserQuestion gets UserQuestion using user id
func (*UserQuestion) AddPoints ¶
func (uq *UserQuestion) AddPoints(amount int64) error
AddPoints Points setter
func (*UserQuestion) GetPoints ¶
func (uq *UserQuestion) GetPoints() (int64, error)
GetPoints Points getter
func (*UserQuestion) GetQuestion ¶
func (uq *UserQuestion) GetQuestion() (*Question, error)
GetQuestion Question getter
func (*UserQuestion) GetUnansweredQuestions ¶
func (uq *UserQuestion) GetUnansweredQuestions() ([]*Question, error)
GetUnansweredQuestions gets all questions user haven't answered
func (*UserQuestion) GetUserQuestions ¶
func (uq *UserQuestion) GetUserQuestions() ([]*Question, error)
GetUserQuestions Questions by the user getter
func (*UserQuestion) RegisterQuestion ¶
func (uq *UserQuestion) RegisterQuestion(questionID int64) error
RegisterQuestion Question setter