resources

package
v0.8.12 Latest Latest
Warning

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

Go to latest
Published: May 14, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GameWinnerValidator validator.Func = func(fl validator.FieldLevel) bool {
	winner, ok := fl.Field().Interface().(model.Winner)
	if ok {
		switch winner {
		case model.RIGHT, model.LEFT, model.DRAW:
			return true
		default:
			return false
		}
	}
	return true
}

Functions

func DeleteAllTournamentPlayers added in v0.8.9

func DeleteAllTournamentPlayers(tournamentParam string, db *gorm.DB) func(*gin.Context)

DeleteAllTournamentPlayers remove all players from a tournament @Summary Remove all players from tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Success 204 @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/players [delete]

func DeletePlayer

func DeletePlayer(param string, db *gorm.DB) func(*gin.Context)

DeletePlayer deletes a player @Summary Delete player @Tags player @Accept json @Produce json @Param id path string true "Player ID" @Success 204 @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /players/{id} [delete]

func DeleteTournament

func DeleteTournament(tournamentParam string, db *gorm.DB) func(*gin.Context)

DeleteTournament removes a tournament @Summary Remove tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Success 204 @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id} [delete]

func DeleteTournamentPlayer

func DeleteTournamentPlayer(tournamentParam string, playerParam string, db *gorm.DB) func(*gin.Context)

DeleteTournamentPlayer removes player from a tournament @Summary Remove player from tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Param player path string true "Player ID" @Success 204 @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/players/{player} [delete]

func DeleteTournamentTable

func DeleteTournamentTable(tournamentParam string, tableParam string, db *gorm.DB) func(*gin.Context)

DeleteTournamentTable deletes a table from a tournament @Summary Remove table from tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Param tableId path string true "Table ID" @Success 204 @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/tables/{tableId} [delete]

func GetGame

func GetGame(param string, db *gorm.DB) func(*gin.Context)

GetGame returns a game played @Summary Get gamne results @Tags game @Accept json @Produce json @Param id path string true "Game ID" @Success 200 {object} model.GameJson @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /games/{id} [get]

func GetGameEvents

func GetGameEvents(param string) func(c *gin.Context)

GetGameEvents creats web socket with tournamnent game events @Summary Opens a web socket for tournamnent game start events @Tags events @Produce json-stream @Param id path string true "Tournament ID" @Success 200 {object} GameStartEventRepresentation @Router /tournaments/{id}/events/game [get]

func GetGameStart

func GetGameStart(param string, db *gorm.DB) func(*gin.Context)

GetGameStart publishes a game start event using web socket @Summary Publishes a game start event @Tags actions @Accept json @Produce json @Param id path string true "Tournament ID" @Success 204 @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/games/start [get]

func GetGames

func GetGames(db *gorm.DB) func(*gin.Context)

GetGames returns all games @Summary Get all gamne results @Tags game @Accept json @Produce json @Success 200 {array} model.GameJson @Router /games [get]

func GetGamesInTournament

func GetGamesInTournament(param string, db *gorm.DB) func(*gin.Context)

GetGamesInTournament find all games in tournament @Summary Get all games in a tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Success 200 {array} model.GameJson @Router /tournaments/{id}/games [get]

func GetPlayer

func GetPlayer(param string, db *gorm.DB) func(*gin.Context)

GetPlayer gets player info @Summary Get player @Tags player @Accept json @Produce json @Param id path string true "Player ID" @Success 200 {object} model.Player @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /players/{id} [get]

func GetPlayerEvents

func GetPlayerEvents(param string) func(c *gin.Context)

GetPlayerEvents creats web socket with tournamnent player events @Summary Opens a web socket for tournamnent player events @Tags events @Produce json-stream @Param id path string true "Tournament ID" @Success 200 {object} TournamentPlayerRepresenatation @Router /tournaments/{id}/events/player [get]

func GetPlayers

func GetPlayers(db *gorm.DB) func(*gin.Context)

GetPlayers get a list of all players @Summary List players @Tags player @Accept json @Produce json @Param exclude query int false "exlude tournament from list" @Success 200 {array} model.Player @Router /players [get]

func GetRandomGames

func GetRandomGames(param string, db *gorm.DB) func(*gin.Context)

GetRandomGames for a tournament @Summary Get random game for a tournament @Tags actions @Accept json @Produce json @Param id path string true "Tournament ID" @Success 200 {array} model.GameJson @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/games/random [get]

func GetTable

func GetTable(param string, db *gorm.DB) func(*gin.Context)

GetTable get info about a table @Summary Get table @Tags table @Accept json @Produce json @Param id path string true "Table ID" @Success 200 {object} model.Table @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tables/{id} [get]

func GetTables

func GetTables(db *gorm.DB) func(*gin.Context)

GetTables get list of all tables @Summary Get all tables @Tags table @Accept json @Produce json @Param exclude query int false "exlude tournament from list" @Success 200 {array} model.Table @Router /tables [get]

func GetTournament

func GetTournament(param string, db *gorm.DB) func(*gin.Context)

GetTournament gets info about a tournament @Summary Get tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Success 200 {object} model.Tournament @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id} [get]

func GetTournamentHistory

func GetTournamentHistory(tournamentParam string, db *gorm.DB) func(*gin.Context)

GetTournamentHistory get ranking history for a given tournament @Summary Get ranking history for a tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Param from query string true "The RFC3339 date to get history from" Format(date) @Success 200 {array} TournamentHistoryRepresenatation @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/history [get]

func GetTournamentPlayeHistory

func GetTournamentPlayeHistory(tournamentParam string, playerParam string, db *gorm.DB) func(*gin.Context)

GetTournamentPlayeHistory get player ranking history in a given tournament @Summary Get player ranking history in tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Param nickname path string true "Player nickname" @Param from query string true "The RFC3339 date to get history from" Format(date) @Success 200 {array} model.TournamentPlayerHistory @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/players/{nickname}/history [get]

func GetTournamentPlayes

func GetTournamentPlayes(param string, db *gorm.DB) func(*gin.Context)

GetTournamentPlayes get players in a given tournament @Summary Get players in tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Success 200 {array} TournamentPlayerRepresenatation @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/players [get]

func GetTournamentTables

func GetTournamentTables(param string, db *gorm.DB) func(*gin.Context)

GetTournamentTables list tables in a tournament @Summary Get tables in a tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Success 200 {array} model.TournamentTable @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/tables [get]

func GetTournaments

func GetTournaments(db *gorm.DB) func(*gin.Context)

GetTournaments gets a list of all tournaments @Summary Get all tournaments @Tags tournament @Accept json @Produce json @Success 200 {array} model.Tournament @Router /tournaments [get]

func HandlePanic

func HandlePanic(c *gin.Context)

HandlePanic provides a defer function to handle panics

func HandlePanicInTransaction

func HandlePanicInTransaction(c *gin.Context, tx *gorm.DB)

HandlePanicInTransaction provides a defer function to handle panics when a transaction has been started

func PostGame

func PostGame(tournamentParam string, tableParam string, db *gorm.DB) func(*gin.Context)

PostGame saves a played game @Summary Submit gamne results @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Param table path string true "Table ID" @Param game body GameResultRequest true "Submit game results" @Success 200 {object} model.GameJson @Failure 400 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/tables/{table}/games [post]

func PostPlayer

func PostPlayer(db *gorm.DB) func(*gin.Context)

PostPlayer creates a new player @Summary Create a new player @Tags player @Accept json @Produce json @Param player body CreatePlayerRequest true "Create player" @Success 201 {object} model.Player @Failure 400 {object} ErrorResponse @Failure 409 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /players [post]

func PostTable

func PostTable(db *gorm.DB) func(*gin.Context)

PostTable creats new table @Summary Create table @Tags table @Accept json @Produce json @Param table body CreateTableRequest true "The table" @Success 200 {object} model.Table @Failure 400 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tables/ [post]

func PostTournament

func PostTournament(db *gorm.DB) func(*gin.Context)

PostTournament creats tournament @Summary Create tournament @Tags tournament @Accept json @Produce json @Param tournament body CreateTournamentRequest true "The tournament" @Success 200 {object} model.Tournament @Failure 400 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments [post]

func PostTournamentPlayer

func PostTournamentPlayer(param string, db *gorm.DB) func(*gin.Context)

PostTournamentPlayer addes player to a tournament @Summary Add player to tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Param player body AddPlayerRequest true "The tournament" @Success 200 {object} TournamentPlayerRepresenatation @Failure 400 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/players [post]

func PostTournamentTables

func PostTournamentTables(param string, db *gorm.DB) func(*gin.Context)

PostTournamentTables adds a table to a tournament @Summary Add table to tournament @Tags tournament @Accept json @Produce json @Param id path string true "Tournament ID" @Param table body AddTableRequest true "The table" @Success 201 {object} model.TournamentTable @Failure 400 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /tournaments/{id}/tables [post]

Types

type AddPlayerRequest

type AddPlayerRequest struct {
	Nickname string `json:"nickname" binding:"required"`
	Ranking  uint   `json:"ranking"`

} //@name AddPlayer

type AddTableRequest

type AddTableRequest struct {
	ID uint `json:"id" binding:"required"`

} //@name AddTable

type CreatePlayerRequest

type CreatePlayerRequest struct {
	Nickname string `json:"nickname" binding:"gte=2,required"`
	RealName string `json:"realname" binding:"gte=2"`
	RFID     string `json:"rfid"`

} //@name CreatePlayer

type CreateTableRequest

type CreateTableRequest struct {
	Name  string      `json:"name" binding:"required"`
	Color model.Color `json:"color" binding:"required"`

} //@name CreateTable

type CreateTournamentRequest

type CreateTournamentRequest struct {
	Name           string `json:"name" binding:"required"`
	GameScore      uint   `json:"score" binding:"required"`
	InitialRanking uint   `json:"initial"  binding:"required"`
	Timeout        uint   `json:"timeout"`

} //@name CreateTournament

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error" binding:"required"`

} //@name Error

ErrorResponse provides an error response for the API

func NewErrorResponse

func NewErrorResponse(error string) *ErrorResponse

NewError creates an new error response

type EventPublisher

type EventPublisher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewEventPublisher

func NewEventPublisher() *EventPublisher

func (*EventPublisher) Get

func (e *EventPublisher) Get(param string) func(c *gin.Context)

func (*EventPublisher) Publish

func (e *EventPublisher) Publish(id string, data interface{})

func (*EventPublisher) Register

func (e *EventPublisher) Register(id string, conn *websocket.Conn)

func (*EventPublisher) Unregister

func (e *EventPublisher) Unregister(id string)

type GameResultRequest

type GameResultRequest struct {
	RightPlayers []string     `json:"rightPlayers" binding:"required,gte=1,lte=2"`
	LeftPlayers  []string     `json:"leftPlayers" binding:"required,gte=1,lte=2"`
	Winner       model.Winner `json:"winner,omitempty" enums:"right,left,draw" binding:"gamewinner,required"`

} //@name GameResult

GameResultRequest represents a played game

type GameStartEventRepresentation

type GameStartEventRepresentation struct {
	Id string `json:"id" binding:"required"`

} //@name GameStartEvent

type TournamentHistoryRepresenatation

type TournamentHistoryRepresenatation struct {
	UpdatedAt time.Time `json:"updated" binding:"required"`
	Nickname  string    `json:"nickname" binding:"required"`
	RealName  string    `json:"realname"`
	Ranking   uint      `json:"ranking" binding:"required"`

} //@name TournamentHistory

type TournamentPlayerRepresenatation

type TournamentPlayerRepresenatation struct {
	Nickname string     `json:"nickname" binding:"required"`
	RealName string     `json:"realname"`
	RFID     string     `json:"rfid,omitempty"`
	Active   bool       `json:"active" binding:"required"`
	Ranking  uint       `json:"ranking,omitempty"`
	Latest   *time.Time `json:"latest,omitempty"`

} //@name TournamentPlayer

TournamentPlayerRepresenatation represents a player in a tournament

Jump to

Keyboard shortcuts

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