repository

package
v0.0.0-...-2cefbdd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountGameMoves

func CountGameMoves(filter string) (int, error)

func CountGames

func CountGames(filter string) (int, error)

func CountPlayers

func CountPlayers(filter string) (int, error)

func CreateGameMove

func CreateGameMove(gameId int64, playerId int64, move string) error

func DeleteGame

func DeleteGame(id int64) error

func DeletePlayer

func DeletePlayer(id int64) error

func FindInactiveGames

func FindInactiveGames() (*[]Game, error)

func PrepareQueryParams

func PrepareQueryParams(filter string, page int, size int, sort string) (string, string, string, []any)

PrepareQueryParams returns where, sort, order, and args parameters used for further building of SQL query. If filter is empty the where param will be an empty string. The filter must match following pattern: (key1)(operator1)(value1);(and|or|not)?;(key2)(operator2)(value2)...

Supported operators: = (equals), != (not equals), <= (less than or equal), >= (greater than or equal), < (less than), > (greater than), ~ (like), !~ (not like), -> (in), !-> (not in)

Example filter: id>=1;or;username=someName;and;startedAt!=null

Returned args will contain at least two values at the end: limit and offset. If where query needs additional parameters, they will be added in args slice.

func QueryGameMoves

func QueryGameMoves(filter string, page int, size int, sort string) (*[]GameMove, error)

func QueryGames

func QueryGames(filter string, page int, size int, sort string) (*[]Game, error)

func QueryPlayers

func QueryPlayers(filter string, page int, size int, sort string) (*[]Player, error)

func RevokeAccessToken

func RevokeAccessToken(token string) error

func SqlDateFormat

func SqlDateFormat(dt sql.NullTime) interface{}

func UpdateGame

func UpdateGame(game *Game) error

func UpdateGamePlayerUsername

func UpdateGamePlayerUsername(playerId int64, username string) error

func UpdatePlayer

func UpdatePlayer(player *Player) error

Types

type AccessToken

type AccessToken struct {
	Id        int64
	PlayerId  int64
	Token     string
	CreatedAt time.Time
	UpdatedAt time.Time
}

func CreateAccessToken

func CreateAccessToken(playerId int64) (*AccessToken, error)

func FindAccessToken

func FindAccessToken(token string) (*AccessToken, error)

type Game

type Game struct {
	Id                  int64
	Name                string
	PasswordHash        sql.NullString
	TurnDurationSeconds sql.NullInt32
	WhitePlayerId       sql.NullInt64
	WhitePlayerUsername sql.NullString
	BlackPlayerId       sql.NullInt64
	BlackPlayerUsername sql.NullString
	CreatorId           sql.NullInt64
	WinnerId            sql.NullInt64
	Tiles               string
	InProgress          bool
	LastMovePlayedAt    sql.NullTime
	StartedAt           sql.NullTime
	EndedAt             sql.NullTime
	CreatedAt           time.Time
	UpdatedAt           time.Time
}

func CreateGame

func CreateGame(name string, password string, turnDurationSeconds int32, creator *Player, white bool, tiles string) (*Game, error)

func FindGameById

func FindGameById(id int64) (*Game, error)

func (*Game) FormatCreatedAt

func (g *Game) FormatCreatedAt() string

func (*Game) FormatEndedAt

func (g *Game) FormatEndedAt() string

func (*Game) FormatLastMovePlayedAt

func (g *Game) FormatLastMovePlayedAt() string

func (*Game) FormatStartedAt

func (g *Game) FormatStartedAt() string

func (*Game) FormatUpdatedAt

func (g *Game) FormatUpdatedAt() string

type GameMove

type GameMove struct {
	Id        int64
	GameId    int64
	PlayerId  sql.NullInt64
	Move      string
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*GameMove) FormatCreatedAt

func (gm *GameMove) FormatCreatedAt() string

func (*GameMove) FormatUpdatedAt

func (gm *GameMove) FormatUpdatedAt() string

type Player

type Player struct {
	Id           int64
	Username     string
	PasswordHash string
	Wins         int32
	Losses       int32
	Draws        int32
	Rate         float32
	Elo          int32
	LastPlayedAt sql.NullTime
	IsPlaying    bool
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

func CreatePlayer

func CreatePlayer(username string, password string) (*Player, error)

func FindPlayerById

func FindPlayerById(id int64) (*Player, error)

func FindPlayerByUsername

func FindPlayerByUsername(username string) (*Player, error)

func (*Player) FormatCreatedAt

func (p *Player) FormatCreatedAt() string

func (*Player) FormatLastPlayedAt

func (p *Player) FormatLastPlayedAt() string

func (*Player) FormatUpdatedAt

func (p *Player) FormatUpdatedAt() string

func (*Player) RefreshIsPlaying

func (p *Player) RefreshIsPlaying()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL