models

package
v0.0.0-...-24a4aaa Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is a simple wrapper around a gorm.DB which has all the methods of the models package.

func CreateDB

func CreateDB(dsn string) (*DB, error)

CreateDB creates a new instance of the gorm database and sets up the migrations

func (*DB) AddTeamMembers

func (db *DB) AddTeamMembers(ms []TeamMember) error

AddTeamMembers adds the given team members to the database.

func (*DB) CreateTeam

func (db *DB) CreateTeam(t *Team) error

CreateTeam creates a new team, which is to say, registers in a tournament.

func (*DB) Session

func (db *DB) Session(id string) (*Session, error)

Session retrieves a session knowing its hashed ID

func (*DB) SetSession

func (db *DB) SetSession(sess *Session) error

SetSession creates or updates a session.

func (*DB) Team

func (db *DB) Team(id ID) (*Team, error)

Team returns a single team knowing its ID.

func (*DB) TeamMembers

func (db *DB) TeamMembers(teamID ID, page int) ([]TeamMember, error)

TeamMembers retrieves all the members of a team.

func (*DB) Teams

func (db *DB) Teams(filters TeamFilters, page int) ([]Team, error)

Teams returns at most 50 teams with the specified page.

func (*DB) Tournament

func (db *DB) Tournament(id ID) (*Tournament, error)

Tournament returns a single tournament knowing its ID.

func (*DB) TournamentRules

func (db *DB) TournamentRules(id ID) (*TournamentRules, error)

TournamentRules returns the tournament rules for the given tournament.

func (*DB) Tournaments

func (db *DB) Tournaments(page int) ([]Tournament, error)

Tournaments returns the tournaments sorted by their ID.

func (*DB) UserInTournament

func (db *DB) UserInTournament(tournID ID, userID int) (bool, error)

UserInTournament checks whether an user is taking part in a tournament.

func (*DB) UserIsBusy

func (db *DB) UserIsBusy(tourn *Tournament, userID int) (bool, error)

UserIsBusy checks whether the user is 'busy' with another tournament during the period in which they would play in the tournament.

type ID

type ID uint64

ID is the ID of a single resource. IDs are similar to Snowflake IDs, in that they are composed of a timestamp and a "step number".

The first 15 least significant bits are reserved to the step number. This is generally a number incremented with each generation of the ID, to ensure uniqueness. Having 15 bits as a step number effectively allows to have 32768 unique ID generations for each timestamp.

The other 49 most significant bits are a unix timestamp in nanoseconds divided by 2^19. This allows for a roughly 0,5 millisecond precision, aside from being much faster than division thanks to bitwise shifting. This allows the timestamp to only roll over at 9353 years from the UNIX epoch, or 2^49 / (1e9*60*60*24*365.25 / 2^19) years, at which point if humans are still around and not dead due to a global catastrophe they probably are not still using something written 9000 years before. To put it in comparison, the 7th millenium BC is when the paleolithic ended and the neolithic started in China.

func GenerateID

func GenerateID() ID

GenerateID creates a new ID.

func (ID) Binary

func (i ID) Binary() []byte

Binary returns the binary representation of ID, like MarshalBinary. The only advantage is that this does not return an error and can be used directly.

func (ID) MarshalBinary

func (i ID) MarshalBinary() ([]byte, error)

MarshalBinary converts the ID into its binary big endian form. It implements encoding.BinaryMarshaler.

func (ID) MarshalText

func (i ID) MarshalText() ([]byte, error)

MarshalText encodes i into its text representation. It is a 11-byte long string composed only of base64 characters.

func (ID) String

func (i ID) String() string

func (ID) Time

func (i ID) Time() time.Time

Time retrieves the time of creation of the ID, by parsing the timestamp in the first 49 bits of the ID.

func (*ID) UnmarshalBinary

func (i *ID) UnmarshalBinary(b []byte) error

UnmarshalBinary decodes b into the ID. It assumed that b is at least 8 bytes long, that it is encoded in big endian, and that i is not nil. It implements encoding.BinaryUnmarshaler.

func (*ID) UnmarshalText

func (i *ID) UnmarshalText(text []byte) error

UnmarshalText decodes i from its text representation. text must be at least 11 bytes long and i must not be nil.

type Session

type Session struct {
	ID          string `json:"-" gorm:"type:char(64);primary_key"`
	UserID      int    `json:"user_id"`
	AccessToken string `json:"access_token"`
	FCMToken    string `json:"-"`
}

Session represents a single user session of an user who has authenticated on Misirlou.

func (Session) RippleClient

func (s Session) RippleClient() *ripple.Client

RippleClient obtains a new ripple.Client to fetch information about the user.

type Team

type Team struct {
	ID         ID     `json:"id"`
	Name       string `json:"name"`
	Tournament ID     `json:"tournament"`
	Captain    int    `json:"captain"`
}

Team represents a team playing in Misirlou.

type TeamAttributes

type TeamAttributes int

TeamAttributes represents the attributes a user may have inside of a team, such as being invited, a member, or a captain.

const (
	TeamAttributeInvited TeamAttributes = iota
	TeamAttributeMember
	TeamAttributeCaptain
)

Various TeamAttributes a team member might have.

type TeamFilters

type TeamFilters struct {
	Tournament      ID
	ForceTournament bool
	Member          int
}

TeamFilters are options that can be passed to Teams for filtering teams.

type TeamMember

type TeamMember struct {
	Team       ID             `json:"team"`
	User       int            `json:"user"`
	Attributes TeamAttributes `json:"attributes"`
}

TeamMember represents a member of a team and information about their relationship to the team.

func (TeamMember) TableName

func (TeamMember) TableName() string

TableName returns the correct table name so that it can correctly be used by gorm.

type Tournament

type Tournament struct {
	ID                ID               `json:"id"`
	Name              string           `json:"name"`
	Description       string           `json:"description"`
	Mode              int              `json:"mode"`
	Status            TournamentStatus `json:"status"`
	StatusData        rawMessageSQL    `json:"status_data"`
	TeamSize          int              `json:"team_size"`
	MinTeamSize       int              `json:"min_team_size"`
	ExclusivityStarts time.Time        `json:"exclusivity_starts"`
	ExclusivityEnds   time.Time        `json:"exclusivity_ends"`
	UpdatedAt         time.Time        `json:"updated_at"`
}

Tournament represents a tournament managed by Misirlou.

type TournamentRules

type TournamentRules struct {
	ID    ID     `json:"id"`
	Rules string `json:"rules"`
}

TournamentRules represents a collection rules set out for a given tournament, which is represented by the ID field in the struct.

type TournamentStaff

type TournamentStaff struct {
	ID         int `json:"id"`
	Tournament ID  `json:"tournament"`
	Privileges int `json:"privileges"`
}

TournamentStaff represents what privileges, if any, a user has in a tournament.

type TournamentStatus

type TournamentStatus int

TournamentStatus represents one of the statuses of the tournament, as described in the constants

const (
	// StatusOrganising means the tournament is currently private as the owner
	// needs to create the rules, staff, etc.
	StatusOrganising TournamentStatus = iota
	// StatusOpen means the tournament currently accepts new teams.
	StatusOpen
	// StatusRegsClosed means that registrations for the tournament have been
	// closed, and we're waiting for a bracket.
	StatusRegsClosed
	// StatusAwaitRound means we're waiting for the next round of the tournament.
	StatusAwaitRound
	// StatusPlaying means the tournament game is currently being played (so, for
	// instance, we need to allow inputs of results of games from referees).
	StatusPlaying
	// StatusClosed means the tournament has been terminated.
	StatusClosed
)

A tournament will always be in one of these states.

Jump to

Keyboard shortcuts

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