player

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Age

func Age(dob, now time.Time) (int, bool)

Age returns the age in whole years on now's date; ok is false when dob is after today (bad data).

func DateOfBirthVisible

func DateOfBirthVisible(viewer role.Role, viewerTeamID, playerTeamID int) bool

DateOfBirthVisible is the rule for who sees a player's date of birth (and age) in the players list: anyone who manages players, since they enter it, and a Manager for players on their own team. Everyone else, such as a Programme Editor, a Photographer or another team's Manager, has no need for it. An unknown or empty role sees nothing: CanEdit, which CanManagePlayers builds on, would let it through.

func PhotoVisible

func PhotoVisible(p Player, teamIsYouth bool, now time.Time) bool

PhotoVisible is the single safeguarding rule for player photos: never for players on a youth team, never for players under 18, and never when the date of birth is nonsensical. Players with no date of birth on a senior team are shown, matching the legacy site.

Types

type CreateInput

type CreateInput struct {
	Name        string
	Position    string
	TeamID      int
	DateOfBirth time.Time
	IsCaptain   bool
}

CreateInput is a new player.

type Handlers

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

Handlers serves /players.

func NewHandlers

func NewHandlers(svc *Service) *Handlers

func (*Handlers) Register

func (h *Handlers) Register(g *echo.Group, guards web.Guards)

Register mounts the player routes on the /api/v1 group.

type Member

type Member struct {
	ID        int    `json:"id"`
	Name      string `json:"name"`
	Position  string `json:"position,omitempty"`
	IsCaptain bool   `json:"isCaptain"`
	ImageURL  string `json:"imageUrl,omitempty"`
}

Member is a player on a public team page: no date of birth.

type Player

type Player struct {
	ID int `db:"id" json:"id"`
	// UUID is the public ID used in file links; see migrations/001.
	UUID        string      `db:"uuid" json:"-"`
	Name        string      `db:"name" json:"name"`
	FileName    null.String `db:"file_name" json:"file_name"`
	DateOfBirth null.Time   `db:"date_of_birth" json:"date_of_birth"`
	Position    null.String `db:"position" json:"position"`
	IsCaptain   bool        `db:"captain" json:"is_captain"`
	TeamID      int         `db:"team_id" json:"team_id"`
}

type Public

type Public struct {
	ID          int        `json:"id"`
	Name        string     `json:"name"`
	Position    string     `json:"position,omitempty"`
	IsCaptain   bool       `json:"isCaptain"`
	DateOfBirth *time.Time `json:"dateOfBirth,omitempty"`
	Age         *int       `json:"age,omitempty"`
	Team        *TeamRef   `json:"team,omitempty"`
	ImageURL    string     `json:"imageUrl,omitempty"`
}

Public is a player as the logged-in players list returns it. ImageURL is empty whenever PhotoVisible says so.

type Service

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

Service is the player business logic.

func NewService

func NewService(store store, teams TeamGetter, files *upload.Files) *Service

func (*Service) Create

func (s *Service) Create(ctx context.Context, in CreateInput, image *upload.File) (Public, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id int) (Public, error)

Delete removes the player and their photo, returning what was deleted.

func (*Service) List

func (s *Service) List(ctx context.Context, viewer role.Role, viewerTeamID int) ([]Public, error)

List returns every player for the players page. Dates of birth are left out where DateOfBirthVisible says viewer may not see them.

func (*Service) PhotoKey

func (s *Service) PhotoKey(ctx context.Context, id string) (string, error)

PhotoKey returns the storage key of the photo of the player with public UUID id, or NotFound when there is none or it must not be shown.

func (*Service) Squad

func (s *Service) Squad(ctx context.Context, t team.Team) ([]Member, error)

Squad lists a team's players for its public page. The caller's t.IsYouth is not trusted; the team is re-read so a stale or wrong value can't expose a youth team's squad. A youth team's squad is hidden entirely (no names, no positions, not just photos), matching the legacy team page. If the team can't be re-read, the squad is hidden too: an unknown team can't be proven to be non-youth, so we fail closed.

func (*Service) Update

func (s *Service) Update(ctx context.Context, id int, in UpdateInput, image *upload.File) (Public, error)

type Store

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

Store stores the dependencies

func NewPlayerRepo

func NewPlayerRepo(db *sqlx.DB) *Store

NewPlayerRepo stores our dependency

func (*Store) AddPlayer

func (s *Store) AddPlayer(ctx context.Context, playerParam Player) (Player, error)

func (*Store) DeletePlayer

func (s *Store) DeletePlayer(ctx context.Context, playerParam Player) error

func (*Store) DetachTeam

func (s *Store) DetachTeam(ctx context.Context, teamID int) error

DetachTeam moves every player on teamID to no team (team_id 0).

func (*Store) EditPlayer

func (s *Store) EditPlayer(ctx context.Context, playerParam Player) (Player, error)

EditPlayer writes p as given. Callers load the row first and change only the fields they mean to, so empty values are deliberate.

func (*Store) GetPlayer

func (s *Store) GetPlayer(ctx context.Context, playerParam Player) (Player, error)

func (*Store) GetPlayers

func (s *Store) GetPlayers(ctx context.Context) ([]Player, error)

func (*Store) GetPlayersTeam

func (s *Store) GetPlayersTeam(ctx context.Context, teamParam team.Team) ([]Player, error)

func (*Store) HasUnder18s

func (s *Store) HasUnder18s(ctx context.Context, teamID int) (bool, error)

HasUnder18s reports whether any player on the team is under 18 today (satisfies team.SquadAges). Players with no date of birth don't count.

type TeamGetter

type TeamGetter interface {
	GetTeam(ctx context.Context, teamParam team.Team) (team.Team, error)
	GetTeams(ctx context.Context) ([]team.Team, error)
}

TeamGetter reads teams (satisfied by *team.Store).

type TeamRef

type TeamRef struct {
	ID      int    `json:"id"`
	Name    string `json:"name"`
	IsYouth bool   `json:"isYouth"`
}

TeamRef is the team a player belongs to.

type UpdateInput

type UpdateInput struct {
	Name        *string
	Position    *string
	TeamID      *int
	DateOfBirth *time.Time
	IsCaptain   *bool
	RemoveImage bool
}

UpdateInput changes a player; nil fields are left unchanged.

Jump to

Keyboard shortcuts

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