model

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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

func (g *Base) IdAsString() string

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 Found

type Found = bool

Found indicating if entity is found in repository

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 NewGame

func NewGame(table *TournamentTable) *Game

NewGame creates a new game

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) GameScore

func (g *Game) GameScore() (uint, uint)

GameScore calculates score for right and left side

func (*Game) GetOrCalculateLeftScore

func (g *Game) GetOrCalculateLeftScore() int

GetOrCalculateLeftScore returns game score for saven games or calculates new score

func (*Game) GetOrCalculateRightScore

func (g *Game) GetOrCalculateRightScore() int

GetOrCalculateRightScore returns game score for saven games or calcukates new score

func (Game) Left

func (g Game) Left() []Player

Left return left playes

func (Game) LeftPlayerNames

func (g Game) LeftPlayerNames() []string

LeftPlayerNames return right player names

func (*Game) MarshalJSON

func (g *Game) MarshalJSON() ([]byte, error)

MarshalJSON creates JSON game representation

func (Game) Right

func (g Game) Right() []Player

Right return right playes

func (Game) RightPlayerNames

func (g Game) RightPlayerNames() []string

RightPlayerNames return right player names

func (*Game) UpdateScore

func (g *Game) UpdateScore() error

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

func NewPlayer

func NewPlayer(nickname, realName string, rfid string) *Player

NewPlayer creates new player

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

func NewTable

func NewTable(name string, color Color) *Table

NewTable creates a new table

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

type Winner

type Winner string

Winner of a game played

Jump to

Keyboard shortcuts

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