models

package
v0.0.0-...-287d283 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InitialSports = []Sport{
	ultimateFrisbee,
	basketball,
	football,
}

Functions

func Hash

func Hash(password string) ([]byte, error)

func VerifyPassword

func VerifyPassword(hashedPassword, password string) error

Types

type Base

type Base struct {
	ID        xid.ID     `gorm:"type:varchar(20);primary_key;" json:"id"`
	Name      string     `gorm:"type:varchar(50);unique" json:"name"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
}

Base is the collection of fields all types in the Skillbased architecture have

type Error

type Error struct {
	Status    int    `json:"status"`
	Message   string `json:"message"`
	Detail    string `json:"detail"`
	RequestID string `json:"request_id"`
}

Error contains the details of a specific error

func GenNotFoundError

func GenNotFoundError(resource, resourceID, requestID string) Error

GenNotFoundError generates a "not found" HTTP error to return to a caller

type Errors

type Errors struct {
	Errors []Error `json:"errors"`
}

Errors is the collection of errors returned to a caller

type GenerateTeamRequest

type GenerateTeamRequest struct {
	Name    string `json:"name"`
	SportID string `json:"sport_id"`

	Players       []Player `json:"players"`
	NumberOfTeams int      `json:"number_of_teams"`
}

type Health

type Health struct {
	Status string `json:"status"`
}

type Player

type Player struct {
	ID   string `json:"id"`
	Name string `json:"name"`

	// Skills is a map relating an existing Sport's ID to a SkillMap (map of skill name to rating out of 10)
	Skills      map[string]SkillMap `json:"skills"`
	PowerScores map[string]float32  `json:"power_scores"`
}

type SkillMap

type SkillMap map[string]int

type SkillWeightMap

type SkillWeightMap map[string]float32

type Sport

type Sport struct {
	Base
	SkillWeights      SkillWeightMap `gorm:"-" json:"skills"` // Ignore this field for DB
	SkillWeightsDB    postgres.Jsonb `json:"-"`               // Ignore this field for JSON
	MaxPlayersPerTeam int            `json:"max_players_per_team"`
}

func (*Sport) AfterFind

func (s *Sport) AfterFind() (err error)

AfterFind is a GORM hook that is used to convert the JSON struct in postgres to the Go map to be returned to the user and operated on by the balancer algorithm

func (*Sport) BeforeCreate

func (s *Sport) BeforeCreate(scope *gorm.Scope) (err error)

BeforeCreate is a GORM hook that is used to convert the Go map to a JSON struct to be stored in postgres

type SportList

type SportList struct {
	NumItems int     `json:"num_items"`
	Items    []Sport `json:"items"`
}

type Team

type Team struct {
	Base

	// Sport is the "parent" sport that this team was created for
	Sport Sport `json:"sport"`

	// PowerScore is the overall "ranking" of this team based on it's player's skills for the given sport, and the
	// weights that sport gives them
	PowerScore float32 `json:"power_score"`

	// Players is the list of players for this team
	Players []Player `json:"players"`
}

Team is a representation of a group of players for a single sport

type TeamSet

type TeamSet struct {
	// User provided name to reference
	Name string `json:"name"`

	CreatedAt time.Time `json:"created_at"`
	ID        string    `json:"id"`
	Sport     Sport     `json:"sport"`
	Teams     []Team    `json:"teams"`
}

TeamSet is the "output" of the team generation algorithm, which represents the collection of teams for a specific sport or season

type User

type User struct {
	ID        uint32    `gorm:"primary_key;auto_increment" json:"id"`
	Username  string    `gorm:"size:255;not null;unique" json:"username"`
	Email     string    `gorm:"size:100;not null;unique" json:"email"`
	Password  string    `gorm:"size:100;not null;" json:"password"`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
}

func (*User) BeforeSave

func (u *User) BeforeSave() error

func (*User) DeleteAUser

func (u *User) DeleteAUser(db *gorm.DB, uid uint32) (int64, error)

func (*User) FindAllUsers

func (u *User) FindAllUsers(db *gorm.DB) (*[]User, error)

func (*User) FindUserByID

func (u *User) FindUserByID(db *gorm.DB, uid uint32) (*User, error)

func (*User) Prepare

func (u *User) Prepare()

func (*User) SaveUser

func (u *User) SaveUser(db *gorm.DB) (*User, error)

func (*User) UpdateAUser

func (u *User) UpdateAUser(db *gorm.DB, uid uint32) (*User, error)

func (*User) Validate

func (u *User) Validate(action string) error

Jump to

Keyboard shortcuts

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