tournaments

package module
v0.0.0-...-e9a9aea Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 18 Imported by: 0

README

tournaments

Documentation

Index

Constants

View Source
const (
	PhaseRegistration   = "registration"
	PhaseInitialization = "initialization"
	PhaseDraft          = "draft"
	PhaseRounds         = "rounds"
	PhaseEnded          = "ended"
)
View Source
const (
	ActionChangeName = "change-name"
	ActionChangeRole = "change-role"
)
View Source
const (
	ActionDelete           = "delete"
	ActionRegisterPlayer   = "register-player"
	ActionDropPlayer       = "drop-player"
	ActionCreate           = "create"
	ActionChangeFormat     = "change-format"
	ActionChangeMaxPlayers = "change-maxplayers"
	ActionEndPhase         = "end-phase"
	ActionEndGame          = "end-game"
	ActionChangeGamesToWin = "change-gamestowin"
)
View Source
const (
	ArgumentTournamentID = "tid"
	ArgumentPlayerID     = "pid"
	ArgumentName         = "name"
	ArgumentRole         = "role"
	ArgumentFormat       = "format"
	ArgumentMaxPlayers   = "maxplayers"
	ArgumentMatch        = "match"
	ArgumentGame         = "game"
	ArgumentGamesToWin   = "gamestowin"
	ArgumentDraw         = "draw"
)

Variables

This section is empty.

Functions

func Codec

func Codec() (*event.Codec, error)

Types

type Claims

type Claims struct {
	Mail string   `json:"mail"`
	ID   PlayerID `json:"id"`
	jwt.StandardClaims
}

type Credentials

type Credentials struct {
	Mail     string `json:"mail"`
	Username string `json:"username"`
	Password string `json:"password"`
}

type Deck

type Deck struct {
	ID   DeckID
	Name string
	Link string
}

func (*Deck) MakeDetailedHyperItem

func (dck *Deck) MakeDetailedHyperItem(resolve hyper.ResolverFunc) hyper.Item

func (*Deck) MakeUndetailedHyperItem

func (dck *Deck) MakeUndetailedHyperItem(resolve hyper.ResolverFunc) hyper.Item

type DeckID

type DeckID string

type DeckRepository

type DeckRepository interface {
	FindAllDecks() ([]Deck, error)
	FindDeckByID(id DeckID) (Deck, error)
	IsDeckNameAvailable(name string) (bool, error)
}

type Game

type Game struct {
	Winner PlayerID `json:"winner"`
	Draw   bool     `json:"draw"`
	Ended  bool     `json:"ended"`
}

type Match

type Match struct {
	Player1 PlayerID `json:"player1"`
	Player2 PlayerID `json:"player2"`
	Winner  PlayerID `json:"winner"`
	P1Count int      `json:"p1Count"`
	P2Count int      `json:"p2Count"`
	Games   []Game   `json:"games"`
	Draw    bool     `json:"draw"`
	Ended   bool     `json:"ended"`
}

type Participant

type Participant struct {
	Player    PlayerID `json:"player"`
	SeatIndex int      `json:"seatIndex"`
	Deck      DeckID   `json:"deck"`
	Matches   int      `json:"matches"`
	Games     int      `json:"games"`
	MatchWins int      `json:"matchWins"`
	GameWins  int      `json:"gameWins"`
}

type Phase

type Phase string

type Player

type Player struct {
	ID          PlayerID       `json:"id,omitempty"`
	Role        string         `json:"role"`
	Version     uint64         `json:"version"`
	Name        string         `json:"name"`
	Tournaments []TournamentID `json:"tournaments"`
	Tracker     TrackerID      `json:"tracker"`
	Mail        string         `json:"mail"`
	Password    string         `json:"password"`
	*event.ChangeRecorder
	Server *Server
}

func LoadPlayer

func LoadPlayer(s *Server, pID PlayerID) (*Player, error)

func LoadPlayers

func LoadPlayers(s *Server, pIDs []PlayerID) ([]*Player, error)

func NewPlayer

func NewPlayer(s *Server) *Player

func (*Player) Apply

func (plr *Player) Apply(e event.Event)

func (*Player) ChangeName

func (plr *Player) ChangeName(name string) error

func (*Player) ChangeRole

func (plr *Player) ChangeRole(role string) error

func (*Player) Create

func (plr *Player) Create(id PlayerID, tracker TrackerID, role string, mail string, password string) error

func (*Player) MakeDetailedHyperItem

func (plr *Player) MakeDetailedHyperItem(resolve hyper.ResolverFunc) hyper.Item

func (*Player) MakeUndetailedHyperItem

func (plr *Player) MakeUndetailedHyperItem(resolve hyper.ResolverFunc) hyper.Item

func (*Player) Mutate

func (plr *Player) Mutate(e event.Event)

func (*Player) RegisterTournament

func (plr *Player) RegisterTournament(tID TournamentID) error

func (*Player) Save

func (plr *Player) Save(es *event.Store, metadata interface{}) error

type PlayerCreated

type PlayerCreated struct {
	ID         string    `json:"id"`
	OccurredOn time.Time `json:"occured-on"`
	Player     PlayerID  `json:"player"`
	Mail       string    `json:"mail"`
	Password   string    `json:"password"`
	Role       string    `json:"role"`
	Tracker    TrackerID `json:"tracker"`
}

type PlayerID

type PlayerID string

type PlayerNameChanged

type PlayerNameChanged struct {
	ID         string    `json:"id"`
	OccurredOn time.Time `json:"occurred-on"`
	Player     PlayerID  `json:"player"`
	Name       string    `json:"name"`
}

type PlayerRepository

type PlayerRepository interface {
	FindAllPlayers() ([]Player, error)
	FindPlayerByID(id PlayerID) (Player, error)
	IsPlayerNameAvailable(name string) (bool, error)
	PlayerExists(id PlayerID) (bool, error)
	IsMailAvailable(mail string) (bool, error)
	FindCredentialsByMail(mail string) (Credentials, PlayerID, error)
}

type PlayerRoleChanged

type PlayerRoleChanged struct {
	ID         string    `json:"id"`
	OccurredOn time.Time `json:"occurred-on"`
	Player     PlayerID  `json:"player"`
	Role       string    `json:"role"`
}

type PlayerTournamentRegistered

type PlayerTournamentRegistered struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Player     PlayerID     `json:"player"`
	Tournament TournamentID `json:"Tournament"`
}

type Projection

type Projection interface {
	TournamentRepository
	PlayerRepository
	DeckRepository
	On(rec event.Record)
	GetVersion() uint64
}

type Seat

type Seat struct {
	Index  int      `json:"index"`
	Player PlayerID `json:"player"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(p Projection, es *event.Store) *Server

func (*Server) HandleGETTracker

func (s *Server) HandleGETTracker(w http.ResponseWriter, r *http.Request)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(dsn string) (*Store, error)

func (*Store) FindAllDecks

func (s *Store) FindAllDecks() ([]Deck, error)

func (*Store) FindAllPlayers

func (s *Store) FindAllPlayers() ([]Player, error)

func (*Store) FindAllTournaments

func (s *Store) FindAllTournaments() ([]Tournament, error)

func (*Store) FindCredentialsByMail

func (s *Store) FindCredentialsByMail(mail string) (Credentials, PlayerID, error)

func (*Store) FindDeckByID

func (s *Store) FindDeckByID(id DeckID) (Deck, error)

func (*Store) FindPlayerByID

func (s *Store) FindPlayerByID(id PlayerID) (Player, error)

func (*Store) FindTournamentByID

func (s *Store) FindTournamentByID(id TournamentID) (Tournament, error)

func (*Store) GetVersion

func (s *Store) GetVersion() uint64

func (*Store) IsDeckNameAvailable

func (s *Store) IsDeckNameAvailable(name string) (bool, error)

func (*Store) IsMailAvailable

func (s *Store) IsMailAvailable(mail string) (bool, error)

func (*Store) IsPlayerNameAvailable

func (s *Store) IsPlayerNameAvailable(name string) (bool, error)

func (*Store) IsTournamentNameAvailable

func (s *Store) IsTournamentNameAvailable(name string) (bool, error)

func (*Store) On

func (s *Store) On(rec event.Record)

func (*Store) PlayerExists

func (s *Store) PlayerExists(ID PlayerID) (bool, error)

type Tournament

type Tournament struct {
	ID           TournamentID  `json:"id"`
	Version      uint64        `json:"version"`
	Name         string        `json:"name"`
	Phase        Phase         `json:"phase"`
	Start        string        `json:"start,omitempty"`
	End          string        `json:"end,omitempty"`
	Format       string        `json:"format,omitempty"`
	MaxPlayers   int           `json:"maxplayers,omitempty"`
	Seats        []Seat        `json:"seats"`
	Matches      []Match       `json:"matches"`
	GamesToWin   int           `json:"gamesToWin"`
	Participants []Participant `json:"players,omitempty"`
	Deleted      bool          `json:"deleted"`
	*event.ChangeRecorder
	Server *Server
}

func LoadTournament

func LoadTournament(s *Server, tID TournamentID) (*Tournament, error)

func NewTournament

func NewTournament(s *Server) *Tournament

func (*Tournament) Apply

func (trn *Tournament) Apply(e event.Event)

func (*Tournament) Begin

func (trn *Tournament) Begin() error

func (*Tournament) ChangeFormat

func (trn *Tournament) ChangeFormat(f string) error

func (*Tournament) ChangeGamesToWin

func (trn *Tournament) ChangeGamesToWin(n int) error

func (*Tournament) ChangeMaxPlayers

func (trn *Tournament) ChangeMaxPlayers(n int) error

func (*Tournament) ChangeName

func (trn *Tournament) ChangeName(name string) error

func (*Tournament) ChangePhase

func (trn *Tournament) ChangePhase(p Phase) error

func (*Tournament) Create

func (trn *Tournament) Create(id TournamentID) error

func (*Tournament) CreateMatches

func (trn *Tournament) CreateMatches() error

func (*Tournament) Delete

func (trn *Tournament) Delete() error

func (*Tournament) DropPlayer

func (trn *Tournament) DropPlayer(pID PlayerID) error

func (*Tournament) EndGame

func (trn *Tournament) EndGame(match int, game int, wnr PlayerID, draw bool) error

func (*Tournament) EndMatch

func (trn *Tournament) EndMatch(match int, wnr PlayerID, draw bool) error

func (*Tournament) Finish

func (trn *Tournament) Finish() error

func (*Tournament) MakeDetailedHyperItem

func (trn *Tournament) MakeDetailedHyperItem(resolve hyper.ResolverFunc) hyper.Item

func (*Tournament) MakeMatches

func (trn *Tournament) MakeMatches()

func (*Tournament) MakeParticipantsHyperItem

func (trn *Tournament) MakeParticipantsHyperItem(resolve hyper.ResolverFunc) (hyper.Item, error)

func (*Tournament) MakeUndetailedHyperItem

func (trn *Tournament) MakeUndetailedHyperItem(resolve hyper.ResolverFunc) hyper.Item

func (*Tournament) Mutate

func (trn *Tournament) Mutate(e event.Event)

func (*Tournament) RegisterPlayer

func (trn *Tournament) RegisterPlayer(pID PlayerID) error

func (*Tournament) Save

func (trn *Tournament) Save(es *event.Store, metadata interface{}) error

type TournamentCreated

type TournamentCreated struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occured-on"`
	Tournament TournamentID `json:"tournament"`
}

type TournamentDeleted

type TournamentDeleted struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
}

type TournamentEnded

type TournamentEnded struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	End        time.Time    `json:"end"`
}

type TournamentFormatChanged

type TournamentFormatChanged struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	Format     string       `json:"format"`
}

type TournamentGameEnded

type TournamentGameEnded struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	Match      int          `json:"match"` //index
	Game       int          `json:"game"`  //index
	Winner     PlayerID     `json:"winner"`
	Draw       bool         `json:"draw"`
}

type TournamentGamesToWinChanged

type TournamentGamesToWinChanged struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	GamesToWin int          `json:"gamesToWin"`
}

type TournamentID

type TournamentID string

type TournamentMatchEnded

type TournamentMatchEnded struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	Match      int          `json:"match"` //index
	Winner     PlayerID     `json:"winner"`
	Draw       bool         `json:"draw"`
}

type TournamentMatchesCreated

type TournamentMatchesCreated struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
}

type TournamentMaxPlayersChanged

type TournamentMaxPlayersChanged struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	MaxPlayers int          `json:"maxplayers"`
}

type TournamentNameChanged

type TournamentNameChanged struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	Name       string       `json:"name"`
}

type TournamentPhaseChanged

type TournamentPhaseChanged struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	Phase      Phase        `json:"phase"`
}

type TournamentPlayerDropped

type TournamentPlayerDropped struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	Player     PlayerID     `json:"player"`
}

type TournamentPlayerRegistered

type TournamentPlayerRegistered struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	Player     PlayerID     `json:"player"`
}

type TournamentRepository

type TournamentRepository interface {
	FindAllTournaments() ([]Tournament, error)
	FindTournamentByID(id TournamentID) (Tournament, error)
	IsTournamentNameAvailable(name string) (bool, error)
}

type TournamentStarted

type TournamentStarted struct {
	ID         string       `json:"id"`
	OccurredOn time.Time    `json:"occurred-on"`
	Tournament TournamentID `json:"tournament"`
	Start      time.Time    `json:"start"`
}

type Tracker

type Tracker struct {
	ID        TrackerID `json:"id"`
	Player    PlayerID  `json:"player"`
	Version   uint64    `json:"version"`
	Matches   int       `json:"matches"`
	MatchWins int       `json:"matchWins"`
	Games     int       `json:"games"`
	GameWins  int       `json:"gameWins"`
	*event.ChangeRecorder
}

func LoadTracker

func LoadTracker(es *event.Store, tID TrackerID) (*Tracker, error)

func NewTracker

func NewTracker() *Tracker

func (*Tracker) Apply

func (trk *Tracker) Apply(e event.Event)

func (*Tracker) Create

func (trk *Tracker) Create(id TrackerID, plr PlayerID) error

func (*Tracker) IncrementGames

func (trk *Tracker) IncrementGames() error

func (*Tracker) IncrementGamesWon

func (trk *Tracker) IncrementGamesWon() error

func (*Tracker) IncrementMatches

func (trk *Tracker) IncrementMatches() error

func (*Tracker) IncrementMatchesWon

func (trk *Tracker) IncrementMatchesWon() error

func (*Tracker) MakeTrackerHyperItem

func (trk *Tracker) MakeTrackerHyperItem(resolve hyper.ResolverFunc) hyper.Item

func (*Tracker) Mutate

func (trk *Tracker) Mutate(e event.Event)

func (*Tracker) Save

func (trk *Tracker) Save(es *event.Store, metadata interface{}) error

type TrackerCreated

type TrackerCreated struct {
	ID         string    `json:"id"`
	OccurredOn time.Time `json:"occurred-on"`
	Tracker    TrackerID `json:"tracker"`
	Player     PlayerID  `json:"player"`
}

type TrackerGamePlayed

type TrackerGamePlayed struct {
	ID         string    `json:"id"`
	OccurredOn time.Time `json:"occurred-on"`
	Tracker    TrackerID `json:"tracker"`
}

type TrackerGameWon

type TrackerGameWon struct {
	ID         string    `json:"id"`
	OccurredOn time.Time `json:"occurred-on"`
	Tracker    TrackerID `json:"tracker"`
}

type TrackerID

type TrackerID string

type TrackerMatchPlayed

type TrackerMatchPlayed struct {
	ID         string    `json:"id"`
	OccurredOn time.Time `json:"occurred-on"`
	Tracker    TrackerID `json:"tracker"`
}

type TrackerMatchWon

type TrackerMatchWon struct {
	ID         string    `json:"id"`
	OccurredOn time.Time `json:"occurred-on"`
	Tracker    TrackerID `json:"tracker"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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