Documentation ¶
Index ¶
- Constants
- type Base
- type Color
- type Found
- type Game
- func (g *Game) AddLeftTournamentPlayer(p *TournamentPlayer) error
- func (g *Game) AddRightTournamentPlayer(p *TournamentPlayer) error
- func (g *Game) AddTournamentPlayer(p *TournamentPlayer) error
- func (g *Game) GameScore() (uint, uint)
- func (g *Game) GetOrCalculateLeftScore() int
- func (g *Game) GetOrCalculateRightScore() int
- func (g Game) Left() []Player
- func (g Game) LeftPlayerNames() []string
- func (g *Game) MarshalJSON() ([]byte, error)
- func (g Game) Right() []Player
- func (g Game) RightPlayerNames() []string
- func (g *Game) UpdateScore() error
- type GameJson
- type GameRepository
- type Player
- type PlayerRepository
- type Table
- type TableRepository
- type Tournament
- type TournamentPlayer
- type TournamentPlayerHistory
- type TournamentRepository
- type TournamentTable
- type Winner
Constants ¶
const ( //RIGHT is winner RIGHT Winner = "right" //LEFT is winner LEFT = "left" //DRAW no winner DRAW = "draw" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct { ID uint `json:"id" binding:"required" gorm:"primary_key"` CreatedAt time.Time `json:"created" binding:"required" gorm:"not null"` UpdatedAt time.Time `json:"updated" binding:"required" gorm:"not null"` DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` }
Base is a gorm model replacment with json tags
func (*Base) IdAsString ¶
type Color ¶
type Color struct { Right string `json:"right" binding:"required" gorm:"type:varchar(50);not null"` Left string `json:"left" binding:"required" gorm:"type:varchar(50);not null"` } //@name Color
Color of table
type Game ¶
type Game struct { Base TournamentTableID uint `gorm:"not null"` TournamentTable TournamentTable `gorm:"not null"` RightPlayerOneID uint `gorm:"not null"` RightPlayerOne TournamentPlayer RightPlayerTwoID uint RightPlayerTwo TournamentPlayer LeftPlayerOneID uint `gorm:"not null"` LeftPlayerOne TournamentPlayer LeftPlayerTwoID uint LeftPlayerTwo TournamentPlayer RightScore int LeftScore int Winner Winner }
Game played
func (*Game) AddLeftTournamentPlayer ¶
func (g *Game) AddLeftTournamentPlayer(p *TournamentPlayer) error
AddLeftTournamentPlayer adds a tournament player to a game
func (*Game) AddRightTournamentPlayer ¶
func (g *Game) AddRightTournamentPlayer(p *TournamentPlayer) error
AddRightTournamentPlayer adds a tournament player to a game
func (*Game) AddTournamentPlayer ¶
func (g *Game) AddTournamentPlayer(p *TournamentPlayer) error
AddTournamentPlayer adds a tournament player to a game
func (*Game) GetOrCalculateLeftScore ¶
GetOrCalculateLeftScore returns game score for saven games or calculates new score
func (*Game) GetOrCalculateRightScore ¶
GetOrCalculateRightScore returns game score for saven games or calcukates new score
func (Game) LeftPlayerNames ¶
LeftPlayerNames return right player names
func (*Game) MarshalJSON ¶
MarshalJSON creates JSON game representation
func (Game) RightPlayerNames ¶
RightPlayerNames return right player names
func (*Game) UpdateScore ¶
UpdateScore set game score for each side on game
type GameJson ¶
type GameJson struct { CreatedAt time.Time `json:"created" binding:"required"` UpdatedAt time.Time `json:"updated" binding:"required"` Table Table `json:"table" binding:"required"` RightPlayers []string `json:"rightPlayers" binding:"required"` LeftPlayers []string `json:"leftPlayers" binding:"required"` RightScore int `json:"rightScore" binding:"required"` LeftScore int `json:"leftScore" binding:"required"` Winner Winner `json:"winner,omitempty"` } //@name Game
type GameRepository ¶
type GameRepository interface { Store(game *Game) Find(id string) (*Game, Found) Remove(id string) Found FindAll() []*Game FindByTournament(id string) []*Game }
GameRepository provides access games etc.
type Player ¶
type Player struct { ID uint `json:"-" binding:"required" gorm:"primary_key"` CreatedAt time.Time `json:"created" binding:"required" gorm:"not null"` UpdatedAt time.Time `json:"updated" binding:"required" gorm:"not null"` DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` Nickname string `json:"nickname" binding:"required" gorm:"size:50;unique_index,not null"` RealName string `json:"realname" gorm:"type:varchar(100)"` RFID string `json:"rfid,omitempty" gorm:"type:varchar(36)"` } //@name Player
Player playing foosball games
type PlayerRepository ¶
type PlayerRepository interface { Store(player *Player) Remove(nickname string) Found Update(player *Player) Find(nickname string) (*Player, Found) FindAll() []*Player FindAllNotInTournament(id string) []*Player FindByTournament(id string) []*Player }
PlayerRepository provides access to players
type Table ¶
type Table struct { Base Name string `json:"name" binding:"required" gorm:"type:varchar(50);not null;index:table_name,unique"` Color Color `json:"color" binding:"required" gorm:"embedded"` } //@name Table
Table used in tournament
type TableRepository ¶
type TableRepository interface { Store(table *Table) Remove(id string) Found Find(id string) (*Table, Found) FindAll() []*Table FindAllNotInTournament(id string) []*Table }
TableRepository provides access games etc.
type Tournament ¶
type Tournament struct { Base Name string `json:"name" binding:"required" gorm:"type:varchar(100);not null"` GameScore uint `json:"score" binding:"required" gorm:"not null"` InitialRanking uint `json:"initial" binding:"required" gorm:"not null"` Timeout uint `json:"timeout" binding:"required" gorm:"default:120"` } //@name Tournament
Tournament played
func NewTournament ¶
func NewTournament(name string) *Tournament
NewTournament creates a new tournament
type TournamentPlayer ¶
type TournamentPlayer struct { Base PlayerID uint `json:"-" gorm:"index:player_tournament,unique;not null"` Player Player `json:"player" binding:"required"` TournamentID uint `json:"-" gorm:"index:player_tournament,unique;not null"` Tournament Tournament `json:"-"` Ranking uint `json:"ranking" binding:"required"` Active bool `json:"active" binding:"required"` Latest *time.Time `json:"latest"` } //@name TournamentPlayer
TournamentPlayer is a player in a tournament
func NewTournamentPlayer ¶
func NewTournamentPlayer(player *Player, tournament *Tournament) *TournamentPlayer
NewTournamentPlayer creates new player in tournament
func NewTournamentPlayerWithRanking ¶
func NewTournamentPlayerWithRanking(player *Player, tournament *Tournament, ranking uint) *TournamentPlayer
NewTournamentPlayer creates new player in tournament
type TournamentPlayerHistory ¶
type TournamentPlayerHistory struct { UpdatedAt time.Time `json:"updated" binding:"required" gorm:"not null"` DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` TournamentPlayerID uint `json:"-" gorm:"index:tournament_player:not null"` TournamentPlayer TournamentPlayer `json:"-"` Ranking uint `json:"ranking" binding:"required" gorm:"not null"` } //@name TournamentPlayerHistory
func NewTournamentPlayerHistory ¶
func NewTournamentPlayerHistory(player *TournamentPlayer) *TournamentPlayerHistory
type TournamentRepository ¶
type TournamentRepository interface { Store(tournament *Tournament) Remove(id string) Found Update(tournament *Tournament) Find(id string) (*Tournament, Found) FindAll() []*Tournament RemoveTable(tournamentId string, tableId string) Found AddTables(tournamentId string, table *Table) (*TournamentTable, Found) FindAllTables(id string) ([]*TournamentTable, Found) FindTable(tournamentId string, tableId string) (*TournamentTable, Found) AddPlayer(tournamentId string, p *Player) (*TournamentPlayer, Found) AddPlayerWithRanking(id string, p *Player, ranking uint) (*TournamentPlayer, Found) FindAllActivePlayers(tournamentId string) ([]*TournamentPlayer, Found) FindPlayer(tournamentId string, nickname string) (*TournamentPlayer, Found) DeactivatePlayer(tournamentId string, nickname string) (*TournamentPlayer, Found) ActivatePlayer(tournamentId string, nickname string) (*TournamentPlayer, Found) RandomGames(id string) ([]*Game, Found) UpdatePlayerRanking(tournamentId string, nickname string, gameScore int, updated time.Time) (*TournamentPlayer, Found) PlayerHistory(tournamentId string, nickname string, from time.Time) ([]*TournamentPlayerHistory, Found) History(tournamentId string, from time.Time) ([]*TournamentPlayerHistory, Found) }
TournamentRepository provides access games etc.
type TournamentTable ¶
type TournamentTable struct { Base TableID uint `json:"-" gorm:"not null"` Table Table `json:"table" binding:"required"` TournamentId uint `json:"-" gorm:"not null"` Tournament Tournament `json:"-"` } //@name TournamentTable
func NewTournamentTable ¶
func NewTournamentTable(tournament *Tournament, table *Table) *TournamentTable
NewTournament creates a new tournament