Documentation
¶
Index ¶
- func Age(dob, now time.Time) (int, bool)
- func DateOfBirthVisible(viewer role.Role, viewerTeamID, playerTeamID int) bool
- func PhotoVisible(p Player, teamIsYouth bool, now time.Time) bool
- type CreateInput
- type Handlers
- type Member
- type Player
- type Public
- type Service
- func (s *Service) Create(ctx context.Context, in CreateInput, image *upload.File) (Public, error)
- func (s *Service) Delete(ctx context.Context, id int) (Public, error)
- func (s *Service) List(ctx context.Context, viewer role.Role, viewerTeamID int) ([]Public, error)
- func (s *Service) PhotoKey(ctx context.Context, id string) (string, error)
- func (s *Service) Squad(ctx context.Context, t team.Team) ([]Member, error)
- func (s *Service) Update(ctx context.Context, id int, in UpdateInput, image *upload.File) (Public, error)
- type Store
- func (s *Store) AddPlayer(ctx context.Context, playerParam Player) (Player, error)
- func (s *Store) DeletePlayer(ctx context.Context, playerParam Player) error
- func (s *Store) DetachTeam(ctx context.Context, teamID int) error
- func (s *Store) EditPlayer(ctx context.Context, playerParam Player) (Player, error)
- func (s *Store) GetPlayer(ctx context.Context, playerParam Player) (Player, error)
- func (s *Store) GetPlayers(ctx context.Context) ([]Player, error)
- func (s *Store) GetPlayersTeam(ctx context.Context, teamParam team.Team) ([]Player, error)
- func (s *Store) HasUnder18s(ctx context.Context, teamID int) (bool, error)
- type TeamGetter
- type TeamRef
- type UpdateInput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Age ¶
Age returns the age in whole years on now's date; ok is false when dob is after today (bad data).
func DateOfBirthVisible ¶
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 ¶
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 ¶
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) List ¶
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 ¶
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 ¶
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.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store stores the dependencies
func (*Store) DeletePlayer ¶
func (*Store) DetachTeam ¶
DetachTeam moves every player on teamID to no team (team_id 0).
func (*Store) EditPlayer ¶
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) GetPlayersTeam ¶
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).