dp

package
v0.0.0-...-c8a53da Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: AGPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimeZoneEnvKey  = "TIME_ZONE"
	DefaultTimezone = "Europe/Berlin"
)
View Source
const (
	VAPIDSubscriberEnvName = "VAPID_SUBSCRIBER"
	VAPIDPublicKeyEnvName  = "VAPID_PUBLIC_KEY"
	VAPIDPrivateKeyEnvName = "VAPID_PRIVATE_KEY"

	PushActionLink PushActionType = "link"
)
View Source
const (
	AnnouncementsCollection = "announcements"
)
View Source
const ClubAdminAccessMiddlewareId = "clubAdminAccess"
View Source
const (
	ClubsCollection = "clubs"
)
View Source
const (
	EventSeriesCollection = "eventseries"
)
View Source
const EventStoreKeyClub = "club"
View Source
const (
	EventsCollection = "events"
)
View Source
const (
	LeagueGroupsCollection = "leaguegroups"
)
View Source
const (
	LocationCollection = "locations"
)
View Source
const (
	ParticipationsCollection = "participations"
)
View Source
const (
	PushSubscriptionsCollection = "pushsubscriptions"
)
View Source
const (
	ServiceEntryCollection = "serviceentries"
)
View Source
const (
	TeamsCollection = "teams"
)
View Source
const UserAccessMiddlewareId = "requireUserAccess"
View Source
const (
	UserCollection = "users"
)

Variables

This section is empty.

Functions

func AddEventParticipationData

func AddEventParticipationData(app core.App, event *core.RecordEnrichEvent) error

func AddSeriesState

func AddSeriesState(e *core.RecordEnrichEvent) error

AddSeriesState is a hook that sets the state of the event series based on the current date

func AddUserICalLink(e *core.RecordEnrichEvent) error

AddUserICalLink adds the user's custom iCal link to the JSON response.

func BindDPHooks

func BindDPHooks(app core.App, client bsm.APIClient, pushService PushService)

func BlockKnownPaths

func BlockKnownPaths(e *core.RequestEvent) error

BlockKnownPaths acts as a simple blocker for some scriptkiddie "attacks" (every 404 response creates a log entry). Not intended to be an actual security measure.

func CreateOrUpdateEventsForSeries

func CreateOrUpdateEventsForSeries(e *core.RecordRequestEvent, mode EventSeriesMode) error

CreateOrUpdateEventsForSeries is the main entry point for event series logic. Triggered on all Create and Update requests (regular API endpoints)

func DeleteEventsForSeries

func DeleteEventsForSeries(e *core.RecordEvent) error

DeleteEventsForSeries deletes all events associated with a given event series record.

func FindRecordProxyByID

func FindRecordProxyByID(app core.App, proxy AppRecordProxy, id string) error

FindRecordProxyByID retrieves a record proxy by its ID from the database. Simple Wrapper for `app.FindRecordById()` to prevent having to load the result manually into a proxy object. Caution: `proxy` needs to be a pointer to a struct that implements AppRecordProxy, not a value.

func ForwardErrorToExternalSystem

func ForwardErrorToExternalSystem(err error, context *ErrorContext, tags *map[string]string)

Forwards the error to the external error tracking system (Sentry-compatible, using self-hosted Bugsink instance).

func GetClubCommunityService

func GetClubCommunityService() func(event *core.RequestEvent) error

func GetGamesCount

func GetGamesCount(app core.App) func(e *core.RequestEvent) error

GetGamesCount returns the number of official league games in the database for a given team and season. Requires a valid auth record that belongs to the team queried.

func GetMD5Hash

func GetMD5Hash(text string) string

GetMD5Hash returns the MD5 hash of the given string. MARK: do not use for anything security-related as this algorithm is considered insecure. Only used for request caching mechanism.

func GetSHA3Hash

func GetSHA3Hash(text string) string

GetSHA3Hash returns the SHA3 hash of the given string.

func GetUserCommunityService

func GetUserCommunityService() func(event *core.RequestEvent) error

func GetUserStats

func GetUserStats() func(event *core.RequestEvent) error

func GetYearStartAndEnd

func GetYearStartAndEnd(year int) (start, end types.DateTime, err error)

func HandleClubPractices

func HandleClubPractices() func(e *core.RequestEvent) error

HandleClubPractices is a handler func that returns all event series for a single club in a format suitable for external systems.

Authentication is expected to be handled by a preceding middleware.

func HideCommunityServiceAdminFields

func HideCommunityServiceAdminFields(e *core.RecordEnrichEvent) error

func HideTeamSignupKey

func HideTeamSignupKey(e *core.RecordEnrichEvent) error

HideTeamSignupKey hides the signup key for a team record if the current user is not an admin.

func ImportLeagueGroups

func ImportLeagueGroups(app core.App, client bsm.LeagueGroupClient, clubID *string, season *int) (err error)

ImportLeagueGroups imports league groups concurrently, either for one given club or all clubs in the database.

func JoinTeam

func JoinTeam(app core.App) func(e *core.RequestEvent) error

func LoadAppTimeZone

func LoadAppTimeZone() (*time.Location, error)

func LogErrorInternalExternal

func LogErrorInternalExternal(app core.App, err error, context *ErrorContext, tags *map[string]string)

LogErrorInternalExternal logs the error to the internal PocketBase logger and forwards it to the external error tracking system.

func NotifyAdminsUserCreation

func NotifyAdminsUserCreation(e *core.RecordEvent, ps PushService) error

NotifyAdminsUserCreation is a hook that handles push notifications to club admins when a new user is created as well as email notifications to superusers.

func NotifyNewAnnouncement

func NotifyNewAnnouncement(e *core.RecordEvent, ps PushService) error

func NotifyNewEvent

func NotifyNewEvent(e *core.RecordEvent, ps PushService) error

NotifyNewEvent sends a push notification to all subscribed team members when a new event is created.

func OAuthUpdateUserData

func OAuthUpdateUserData(e *core.RecordAuthWithOAuth2RequestEvent) error

OAuthUpdateUserData updates user record with information found in the OAuth2 response.

This could also be used to validate the signup key, but does not do that at the moment (see generic record creation hook that also works for password auth).

func PushTeamOrClubAnnouncement

func PushTeamOrClubAnnouncement(app core.App, coll string, announcement *Announcement, recordID string, ps PushService)

PushTeamOrClubAnnouncement sends a push notification to all subscribed users when a new announcement is created for a team or club.

func RequireClubAdminAccess

func RequireClubAdminAccess() *hook.Handler[*core.RequestEvent]

RequireClubAdminAccess verifies that the current auth is an admin for the club. The club is expected to be provided via the path parameter `club`.

func RequireUserAccess

func RequireUserAccess(record *core.Record) *hook.Handler[*core.RequestEvent]

RequireUserAccess verifies that the current auth can access a record in a request param. In DiamondPlanner context, that is most commonly used for `users` and means one (or more) of 3 things:

  • the user is the auth record itself
  • the auth record is an admin of one of the requested user's teams
  • the auth record is an admin of one of the requested user's clubs

func SetDisplayName

func SetDisplayName(e *core.RecordEvent) error

SetDisplayName sets the display name for the user if it is not already set.

Default display name format: first name + first letter of last name + dot

func SetLastLogin

func SetLastLogin(app core.App, record *core.Record) (err error)

func StartLeagueGroupsImport

func StartLeagueGroupsImport(app core.App, client bsm.APIClient) func(event *core.RequestEvent) error

StartLeagueGroupsImport runs import cron for league groups exactly once for one specific club.

func TriggerLeagueImport

func TriggerLeagueImport(app core.App, client bsm.APIClient, event *core.RecordsListRequestEvent) error

TriggerLeagueImport called on every league group listing if the result is empty and special query parameters `season` and `club` are sent, an import is automatically triggered.

func ValidateEvent

func ValidateEvent(e *core.RecordEvent) error

func ValidateEventTimes

func ValidateEventTimes(e *core.RecordRequestEvent) error

ValidateEventTimes ensures that event times are valid and within the expected range.

func ValidateSignupKey

func ValidateSignupKey(e *core.RecordRequestEvent) error

ValidateSignupKey checks that a valid signup key is used on user creation. A user is assigned a team and club based on the signup key used.

Superuser auth bypasses this check (so creating users from PocketBase admin panel is always possible).

Types

type Announcement

type Announcement struct {
	core.BaseRecordProxy
}

Announcement RecordProxy for collection `announcements`. Provides type-safe struct access to announcement records.

func (*Announcement) Author

func (a *Announcement) Author() string

func (*Announcement) BodyText

func (a *Announcement) BodyText() string

func (*Announcement) Club

func (a *Announcement) Club() string
func (a *Announcement) Link() string

func (*Announcement) LinkText

func (a *Announcement) LinkText() string

func (*Announcement) Priority

func (a *Announcement) Priority() string

func (*Announcement) SetAuthor

func (a *Announcement) SetAuthor(authorID string)

func (*Announcement) SetBodyText

func (a *Announcement) SetBodyText(bodyText string)

func (*Announcement) SetClub

func (a *Announcement) SetClub(clubID string)
func (a *Announcement) SetLink(link string)

func (*Announcement) SetLinkText

func (a *Announcement) SetLinkText(linkText string)

func (*Announcement) SetPriority

func (a *Announcement) SetPriority(priority string)

func (*Announcement) SetTeam

func (a *Announcement) SetTeam(teamID string)

func (*Announcement) SetTitle

func (a *Announcement) SetTitle(title string)

func (*Announcement) Team

func (a *Announcement) Team() string

func (*Announcement) Title

func (a *Announcement) Title() string

type AppRecordProxy

type AppRecordProxy interface {
	core.RecordProxy
	ID() string
	CollectionName() string
}

AppRecordProxy defines the interface for all Diamond Planner Record Proxies used for type-safe access to record model fields.

type AttendanceTotal

type AttendanceTotal struct {
	Type     EventType `json:"type"`
	Attended int       `json:"attended"`
	Total    int       `json:"total"`
}

type Club

type Club struct {
	core.BaseRecordProxy
}

Club RecordProxy for collection `clubs`. Provides type-safe struct access to club records.

func (*Club) Acronym

func (c *Club) Acronym() string

func (*Club) AdminEmail

func (c *Club) AdminEmail() string

func (*Club) Admins

func (c *Club) Admins() []string

func (*Club) BSMAPIKey

func (c *Club) BSMAPIKey() string

func (*Club) BSMID

func (c *Club) BSMID() int

func (*Club) BSMSearchString

func (c *Club) BSMSearchString() string

func (*Club) CollectionName

func (c *Club) CollectionName() string

func (*Club) ID

func (c *Club) ID() string

func (*Club) Name

func (c *Club) Name() string

func (*Club) ServiceRequirement

func (c *Club) ServiceRequirement() int

func (*Club) SetAcronym

func (c *Club) SetAcronym(acronym string)

func (*Club) SetAdminEmail

func (c *Club) SetAdminEmail(email string)

func (*Club) SetAdmins

func (c *Club) SetAdmins(adminIDs []string)

func (*Club) SetBSMAPIKey

func (c *Club) SetBSMAPIKey(key string)

func (*Club) SetBSMID

func (c *Club) SetBSMID(id int)

func (*Club) SetBSMSearchString

func (c *Club) SetBSMSearchString(searchString string)

func (*Club) SetName

func (c *Club) SetName(name string)

func (*Club) SetServiceRequirement

func (c *Club) SetServiceRequirement(req int)

func (*Club) SetTeamName

func (c *Club) SetTeamName(teamName string)

func (*Club) TeamName

func (c *Club) TeamName() string

type ClubCommunityServiceRow

type ClubCommunityServiceRow struct {
	ID           string `db:"id" json:"id"`
	Email        string `db:"email" json:"email"`
	Name         string `db:"name" json:"name"`
	Target       *int   `db:"target" json:"target"`
	TotalMinutes int    `db:"total_minutes" json:"total_minutes"`
	TargetMet    bool   `db:"target_met" json:"target_met"`
}

type DiamondPlanner

type DiamondPlanner struct {
	*pocketbase.PocketBase
}

func NewDiamondPlanner

func NewDiamondPlanner(client bsm.APIClient, pushService PushService) *DiamondPlanner

type ErrorContext

type ErrorContext struct {
	Key    string
	Values map[string]any
}

type Event

type Event struct {
	core.BaseRecordProxy
}

Event RecordProxy for collection `events`. Provides type-safe struct access to event records.

func EventSeriesLinkedListToSlice

func EventSeriesLinkedListToSlice(list *list.List) (events []*Event, err error)

EventSeriesLinkedListToSlice adds persistence info to an event series and returns a slice of events.

func (*Event) AddAdditionalTeam

func (e *Event) AddAdditionalTeam(team string)

func (*Event) AdditionalTeams

func (e *Event) AdditionalTeams() []string

func (*Event) Attire

func (e *Event) Attire() string

func (*Event) BSMID

func (e *Event) BSMID() int

func (*Event) Club

func (e *Event) Club() string

func (*Event) CollectionName

func (e *Event) CollectionName() string

func (*Event) Created

func (e *Event) Created() types.DateTime

func (*Event) Desc

func (e *Event) Desc() string

func (*Event) EndTime

func (e *Event) EndTime() types.DateTime

func (*Event) Guests

func (e *Event) Guests() string

func (*Event) HasAdditionalTeams

func (e *Event) HasAdditionalTeams() bool

func (*Event) ID

func (e *Event) ID() string

func (*Event) IsCancelled

func (e *Event) IsCancelled() bool

func (*Event) Location

func (e *Event) Location() string

func (*Event) MatchJSON

func (e *Event) MatchJSON() string

func (*Event) MeetingTime

func (e *Event) MeetingTime() types.DateTime

func (*Event) Series

func (e *Event) Series() string

func (*Event) SetAdditionalTeams

func (e *Event) SetAdditionalTeams(additionalTeams []string)

func (*Event) SetAttire

func (e *Event) SetAttire(attire string)

func (*Event) SetBSMID

func (e *Event) SetBSMID(bsmID int)

func (*Event) SetCancelled

func (e *Event) SetCancelled(cancelled bool)

func (*Event) SetClub

func (e *Event) SetClub(club string)

func (*Event) SetDesc

func (e *Event) SetDesc(desc string)

func (*Event) SetEndTime

func (e *Event) SetEndTime(endTime types.DateTime)

func (*Event) SetGuests

func (e *Event) SetGuests(guests string)

func (*Event) SetLocation

func (e *Event) SetLocation(location string)

func (*Event) SetMatchJSON

func (e *Event) SetMatchJSON(matchJSON string)

func (*Event) SetMeetingTime

func (e *Event) SetMeetingTime(meetingTime types.DateTime)

func (*Event) SetParticipations

func (e *Event) SetParticipations(participations ParticipationsByType)

SetParticipations sets a virtual (non-DB) field to include participation data (back-relation).

func (*Event) SetSeries

func (e *Event) SetSeries(series string)

func (*Event) SetStartTime

func (e *Event) SetStartTime(startTime types.DateTime)

func (*Event) SetTeam

func (e *Event) SetTeam(team string)

func (*Event) SetTitle

func (e *Event) SetTitle(title string)

func (*Event) SetType

func (e *Event) SetType(eventType string)

func (*Event) SetUserParticipation

func (e *Event) SetUserParticipation(participation *core.Record)

SetUserParticipation sets a virtual (non-DB) field to include participation data for the currently-logged-in user.

func (*Event) StartTime

func (e *Event) StartTime() types.DateTime

func (*Event) Team

func (e *Event) Team() string

func (*Event) Title

func (e *Event) Title() string

func (*Event) Type

func (e *Event) Type() string

func (*Event) Updated

func (e *Event) Updated() types.DateTime

type EventCounts

type EventCounts struct {
	Games     int `db:"games"`
	Practices int `db:"practices"`
	Misc      int `db:"misc"`
	AllEvents int `db:"all_events"`
}

func GetEventCounts

func GetEventCounts(app core.App, user *core.Record, season string, team string, excludeFutureEvents bool) (EventCounts, error)

type EventSeries

type EventSeries struct {
	core.BaseRecordProxy
}

EventSeries is a RecordProxy for the `eventseries` collection. It offers type-safe getters and setters for every field.

Pure database model, relations are not resolved automatically.

func (*EventSeries) AddAdditionalTeam

func (s *EventSeries) AddAdditionalTeam(team string)

func (*EventSeries) AdditionalTeams

func (s *EventSeries) AdditionalTeams() []string

AdditionalTeams returns the additional teams associated with the series.

func (*EventSeries) CollectionName

func (s *EventSeries) CollectionName() string

func (*EventSeries) Desc

func (s *EventSeries) Desc() string

Desc returns the optional description.

func (*EventSeries) DetermineState

func (s *EventSeries) DetermineState() SeriesState

func (*EventSeries) Duration

func (s *EventSeries) Duration() int

Duration returns the duration of an event in the series (in minutes).

func (*EventSeries) ID

func (s *EventSeries) ID() string

ID returns the record id.

func (*EventSeries) Interval

func (s *EventSeries) Interval() int

Interval returns the number of days between occurrences of events in the series.

func (*EventSeries) Location

func (s *EventSeries) Location() string

Location returns the location string.

func (*EventSeries) SeriesEnd

func (s *EventSeries) SeriesEnd() types.DateTime

SeriesEnd returns the last day/time of the series.

func (*EventSeries) SeriesStart

func (s *EventSeries) SeriesStart() types.DateTime

SeriesStart returns the first day/time of the series.

func (*EventSeries) SetAdditionalTeams

func (s *EventSeries) SetAdditionalTeams(teams []string)

func (*EventSeries) SetDesc

func (s *EventSeries) SetDesc(desc string)

func (*EventSeries) SetDuration

func (s *EventSeries) SetDuration(duration int)

func (*EventSeries) SetInterval

func (s *EventSeries) SetInterval(interval int)

func (*EventSeries) SetLocation

func (s *EventSeries) SetLocation(location string)

func (*EventSeries) SetSeriesEnd

func (s *EventSeries) SetSeriesEnd(end types.DateTime)

func (*EventSeries) SetSeriesStart

func (s *EventSeries) SetSeriesStart(start types.DateTime)

func (*EventSeries) SetState

func (s *EventSeries) SetState(state SeriesState)

func (*EventSeries) SetTeam

func (s *EventSeries) SetTeam(team string)

func (*EventSeries) SetTitle

func (s *EventSeries) SetTitle(title string)

func (*EventSeries) Team

func (s *EventSeries) Team() string

Team returns the id of the team the series belongs to.

func (*EventSeries) Title

func (s *EventSeries) Title() string

Title returns the series title.

func (*EventSeries) ToPracticeDTO

func (s *EventSeries) ToPracticeDTO(loc *time.Location) *PracticeDTO

ToPracticeDTO converts an event series to a PracticeDTO.

The returned pointer is never nil.

type EventSeriesAction

type EventSeriesAction string
const (
	CreateEventsAction       EventSeriesAction = "create"
	UpdateFutureEventsAction EventSeriesAction = "update-future"
	UpdateAllEventsAction    EventSeriesAction = "update-all"
)

type EventSeriesMode

type EventSeriesMode string
const (
	CreateEventSeriesMode EventSeriesMode = "create"
	UpdateEventSeriesMode EventSeriesMode = "update"
)

type EventType

type EventType string
const (
	Game     EventType = "game"
	Practice EventType = "practice"
	Misc     EventType = "misc"
	All      EventType = "all"
)

func ParseEventType

func ParseEventType(s string) (EventType, error)

func (EventType) IsValid

func (et EventType) IsValid() bool

func (EventType) String

func (et EventType) String() string

type GameImportService

type GameImportService struct {
	App GameImportServiceApp
}

func (GameImportService) Client

func (s GameImportService) Client() bsm.APIClient

func (GameImportService) ImportGames

func (s GameImportService) ImportGames()

type GameImportServiceApp

type GameImportServiceApp interface {
	FindRecordsByFilter(
		collectionModelOrIdentifier any,
		filter string,
		sort string,
		limit int,
		offset int,
		params ...dbx.Params,
	) ([]*core.Record, error)
	FindFirstRecordByData(collectionModelOrIdentifier any, key string, value any) (*core.Record, error)
	Logger() *slog.Logger
	ExpandRecord(record *core.Record, expands []string, optFetchFunc core.ExpandFetchFunc) map[string]error
	FindCollectionByNameOrId(nameOrId string) (*core.Collection, error)
	Save(model core.Model) error
}

type JoinTeamPayload

type JoinTeamPayload struct {
	UserID    string `json:"userID"`
	SignupKey string `json:"signupKey"`
}

type LeagueGroup

type LeagueGroup struct {
	core.BaseRecordProxy
}

LeagueGroup RecordProxy for collection `leaguegroups`. Provides type-safe struct access to league group records.

func (*LeagueGroup) Acronym

func (lg *LeagueGroup) Acronym() string

func (*LeagueGroup) BSMID

func (lg *LeagueGroup) BSMID() int

func (*LeagueGroup) Clubs

func (lg *LeagueGroup) Clubs() []string

func (*LeagueGroup) CollectionName

func (lg *LeagueGroup) CollectionName() string

func (*LeagueGroup) ID

func (lg *LeagueGroup) ID() string

func (*LeagueGroup) Name

func (lg *LeagueGroup) Name() string

func (*LeagueGroup) Season

func (lg *LeagueGroup) Season() int

func (*LeagueGroup) SetAcronym

func (lg *LeagueGroup) SetAcronym(acronym string)

func (*LeagueGroup) SetBSMID

func (lg *LeagueGroup) SetBSMID(bsmID int)

func (*LeagueGroup) SetClubs

func (lg *LeagueGroup) SetClubs(clubs []string)

func (*LeagueGroup) SetName

func (lg *LeagueGroup) SetName(name string)

func (*LeagueGroup) SetSeason

func (lg *LeagueGroup) SetSeason(season int)

type Location

type Location struct {
	core.BaseRecordProxy
}

Location RecordProxy for collection `locations`.

func (*Location) AddressAddon

func (l *Location) AddressAddon() string

AddressAddon for many BSM datasets contains the actual name of the field

func (*Location) BSMID

func (l *Location) BSMID() int

func (*Location) City

func (l *Location) City() string

func (*Location) Club

func (l *Location) Club() string

func (*Location) CollectionName

func (l *Location) CollectionName() string

func (*Location) Country

func (l *Location) Country() string

func (*Location) Description

func (l *Location) Description() string

func (*Location) GetCalendarFormatted

func (l *Location) GetCalendarFormatted() string

func (*Location) GroundRules

func (l *Location) GroundRules() string

func (*Location) HumanCountry

func (l *Location) HumanCountry() string

func (*Location) ID

func (l *Location) ID() string

func (*Location) InternalName

func (l *Location) InternalName() string

func (*Location) Latitude

func (l *Location) Latitude() float64

func (*Location) Longitude

func (l *Location) Longitude() float64

func (*Location) Name

func (l *Location) Name() string

Name contains mostly useless data like "Baseball" there is also `internal_name` in the record model to have a field that automatic imports do not overwrite

func (*Location) OtherInformation

func (l *Location) OtherInformation() string

func (*Location) PhotoURL

func (l *Location) PhotoURL() string

func (*Location) PostalCode

func (l *Location) PostalCode() string

func (*Location) SetAddressAddon

func (l *Location) SetAddressAddon(addressAddon string)

func (*Location) SetBSMID

func (l *Location) SetBSMID(bsmID int)

func (*Location) SetCity

func (l *Location) SetCity(city string)

func (*Location) SetClub

func (l *Location) SetClub(club string)

func (*Location) SetCountry

func (l *Location) SetCountry(country string)

func (*Location) SetDescription

func (l *Location) SetDescription(description string)

func (*Location) SetGroundRules

func (l *Location) SetGroundRules(groundRules string)

func (*Location) SetHumanCountry

func (l *Location) SetHumanCountry(humanCountry string)

func (*Location) SetInternalName

func (l *Location) SetInternalName(internalName string)

func (*Location) SetLatitude

func (l *Location) SetLatitude(latitude float64)

func (*Location) SetLongitude

func (l *Location) SetLongitude(longitude float64)

func (*Location) SetName

func (l *Location) SetName(name string)

func (*Location) SetOtherInformation

func (l *Location) SetOtherInformation(otherInformation string)

func (*Location) SetPhotoURL

func (l *Location) SetPhotoURL(photoURL string)

func (*Location) SetPostalCode

func (l *Location) SetPostalCode(postalCode string)

func (*Location) SetSpectatorSeats

func (l *Location) SetSpectatorSeats(spectatorSeats int)

func (*Location) SetSpectatorTotal

func (l *Location) SetSpectatorTotal(spectatorTotal int)

func (*Location) SetStreet

func (l *Location) SetStreet(street string)

func (*Location) SpectatorSeats

func (l *Location) SpectatorSeats() int

func (*Location) SpectatorTotal

func (l *Location) SpectatorTotal() int

func (*Location) Street

func (l *Location) Street() string

func (*Location) String

func (l *Location) String() string

func (*Location) ToDTO

func (l *Location) ToDTO() *LocationDTO

type LocationDTO

type LocationDTO struct {
	Name         string  `json:"name"`
	AddressAddon string  `json:"address_addon"`
	InternalName string  `json:"internal_name"`
	Latitude     float64 `json:"latitude"`
	Longitude    float64 `json:"longitude"`
	Street       string  `json:"street"`
	PostalCode   string  `json:"postal_code"`
	City         string  `json:"city"`
	Country      string  `json:"country"`
	BSMID        int     `json:"bsm_id"`
}

type LogOnlyApp

type LogOnlyApp interface {
	Logger() *slog.Logger
}

LogOnlyApp is a PocketBase app that only needs to log errors.

type LogicError

type LogicError struct {
	Message string
}

func (LogicError) Error

func (e LogicError) Error() string

type NamedRecordProxy

type NamedRecordProxy interface {
	core.RecordProxy
	Name() string
}

type NotAuthorizedError

type NotAuthorizedError struct {
	Message string
}

func (*NotAuthorizedError) Error

func (e *NotAuthorizedError) Error() string

type ParticipationStatsByPerson

type ParticipationStatsByPerson struct {
	ID         string `db:"id" json:"id"`
	LastName   string `db:"last_name" json:"lastName"`
	FirstName  string `db:"first_name" json:"firstName"`
	Type       string `db:"type" json:"type"`
	InCount    int    `db:"inCount" json:"inCount"`
	OutCount   int    `db:"outCount" json:"outCount"`
	MaybeCount int    `db:"maybeCount" json:"maybeCount"`
	TotalCount int    `db:"TotalCount" json:"totalCount"`
}

func GetParticipationStats

func GetParticipationStats(user *core.Record, app core.App, seasonParam string, eventTypeParam string, team string) ([]ParticipationStatsByPerson, error)

type ParticipationTotal

type ParticipationTotal struct {
	Type   ParticipationType `json:"type"`
	Amount int               `json:"amount"`
}

type ParticipationType

type ParticipationType string
const (
	In    ParticipationType = "in"
	Out   ParticipationType = "out"
	Maybe ParticipationType = "maybe"
)

func ParseParticipationType

func ParseParticipationType(s string) (ParticipationType, error)

func (ParticipationType) IsValid

func (pt ParticipationType) IsValid() bool

func (ParticipationType) String

func (pt ParticipationType) String() string

type ParticipationsByType

type ParticipationsByType struct {
	In          []*core.Record         `json:"in"`
	Out         []*core.Record         `json:"out"`
	Maybe       []*core.Record         `json:"maybe"`
	Unspecified []UserParticipationDTO `json:"unspecified"`
}

type PersonalAttendanceStatsItem

type PersonalAttendanceStatsItem struct {
	Season              int                          `json:"season"`
	TotalPossibleEvents int                          `json:"totalPossibleEvents"`
	AttendanceTotals    []AttendanceTotal            `json:"attendanceTotals"`
	ParticipationTotals []ParticipationTotal         `json:"participationTotals"`
	Type                EventType                    `json:"type"`
	Values              []ParticipationStatsByPerson `json:"values"`
	TeamName            string                       `json:"teamName"`
}

func LoadUserStats

func LoadUserStats(user *core.Record, requestEvent *core.RequestEvent) (PersonalAttendanceStatsItem, error)

LoadUserStats gets participation stats by event type and participation state

type PracticeDTO

type PracticeDTO struct {
	ID             string         `json:"id"`
	Teams          []string       `json:"teams"`
	Season         PracticeSeason `json:"season"`
	HumanSeason    string         `json:"human_season"`
	DayOfWeek      time.Weekday   `json:"day_of_week"`
	HumanDayOfWeek string         `json:"human_day_of_week"`
	StartTime      string         `json:"start_time"`
	EndTime        string         `json:"end_time"`
	Desc           string         `json:"desc"`
	Location       *LocationDTO   `json:"location"`
}

PracticeDTO represents a single event series in a calendaric format.

type PracticeSeason

type PracticeSeason uint8

PracticeSeason represents summer or winter in practice context.

const (
	PracticeSeasonSummer PracticeSeason = 0
	PracticeSeasonWinter PracticeSeason = 1
)

func (PracticeSeason) String

func (ps PracticeSeason) String() string

String returns a string representation of the underlying integer constant.

type PushActionData

type PushActionData struct {
	Action PushActionType `json:"action"`
	Title  string         `json:"title"`
	Type   string         `json:"type"`
}

type PushActionType

type PushActionType string

type PushMessage

type PushMessage struct {
	Title   string           `json:"title"`
	Body    string           `json:"body"`
	Data    map[string]any   `json:"data"`
	Tag     string           `json:"tag"`
	Actions []PushActionData `json:"actions"`
}

PushMessage represents the raw data for a push notification message that is encoded into the JSON payload. Closely follows the DOM type `NotificationOptions`.

type PushService

type PushService interface {
	SendPushMessage(msg *PushMessage, sub *webpush.Subscription) error
	// contains filtered or unexported methods
}

PushService defines the app-wide interface for sending push notifications.

func NewPushService

func NewPushService() PushService

NewPushService creates a new PushServiceImpl instance, making sure the VAPID credentials are present in the environment.

type PushServiceImpl

type PushServiceImpl struct {
	Subscriber      string
	VAPIDPublicKey  string
	VAPIDPrivateKey string
}

PushServiceImpl is the default implementation of PushService. It is meant as a singleton, to be instantiated only once. The main advantage is that it encapsulates the VAPID credentials and handles the actual sending of push notifications.

func (PushServiceImpl) SendPushMessage

func (p PushServiceImpl) SendPushMessage(msg *PushMessage, sub *webpush.Subscription) error

SendPushMessage sends a push notification to the given subscription.

type PushSubscription

type PushSubscription struct {
	core.BaseRecordProxy
}

PushSubscription RecordProxy for collection `pushsubscriptions`. Provides type-safe struct access to push subscription records.

func GetSubscriptionsForTeamOrClub

func GetSubscriptionsForTeamOrClub(id string, coll string, app core.App) ([]PushSubscription, error)

func GetSubscriptionsForUserIDs

func GetSubscriptionsForUserIDs(userIDs []string, app core.App) ([]PushSubscription, error)

func (*PushSubscription) CollectionName

func (p *PushSubscription) CollectionName() string

func (*PushSubscription) Encoding

func (p *PushSubscription) Encoding() string

func (*PushSubscription) Endpoint

func (p *PushSubscription) Endpoint() string

func (*PushSubscription) ID

func (p *PushSubscription) ID() string

func (*PushSubscription) KeyAuth

func (p *PushSubscription) KeyAuth() string

func (*PushSubscription) KeyP256dh

func (p *PushSubscription) KeyP256dh() string

func (*PushSubscription) SetEncoding

func (p *PushSubscription) SetEncoding(encoding string)

func (*PushSubscription) SetEndpoint

func (p *PushSubscription) SetEndpoint(endpoint string)

func (*PushSubscription) SetKeyAuth

func (p *PushSubscription) SetKeyAuth(key string)

func (*PushSubscription) SetKeyP256dh

func (p *PushSubscription) SetKeyP256dh(key string)

func (*PushSubscription) SetUser

func (p *PushSubscription) SetUser(userId string)

func (*PushSubscription) ToWebPushSubscription

func (p *PushSubscription) ToWebPushSubscription() webpush.Subscription

ToWebPushSubscription converts a Diamond Planner push subscription record from the database to a webpush.Subscription to be sent via external browser-vendored Push Service.

func (*PushSubscription) User

func (p *PushSubscription) User() string

type ResponseStatus

type ResponseStatus string
const (
	ResponseStatusSuccess ResponseStatus = "success"
	ResponseStatusError   ResponseStatus = "error"
)

type SeriesState

type SeriesState string
const (
	SeriesStateFuture  SeriesState = "future"
	SeriesStatePast    SeriesState = "past"
	SeriesStateOngoing SeriesState = "ongoing"
)

type ServiceEntry

type ServiceEntry struct {
	core.BaseRecordProxy
}

ServiceEntry RecordProxy for collection `serviceentries`. Provides type-safe struct access to service entry records.

func (*ServiceEntry) AdminComment

func (s *ServiceEntry) AdminComment() string

func (*ServiceEntry) BoardMember

func (s *ServiceEntry) BoardMember() string

func (*ServiceEntry) Club

func (s *ServiceEntry) Club() string

func (*ServiceEntry) CollectionName

func (s *ServiceEntry) CollectionName() string

func (*ServiceEntry) Description

func (s *ServiceEntry) Description() string

func (*ServiceEntry) HideAdminFields

func (s *ServiceEntry) HideAdminFields()

func (*ServiceEntry) ID

func (s *ServiceEntry) ID() string

func (*ServiceEntry) Member

func (s *ServiceEntry) Member() string

func (*ServiceEntry) Minutes

func (s *ServiceEntry) Minutes() int

func (*ServiceEntry) ServiceDate

func (s *ServiceEntry) ServiceDate() types.DateTime

func (*ServiceEntry) SetAdminComment

func (s *ServiceEntry) SetAdminComment(comment string)

func (*ServiceEntry) SetBoardMember

func (s *ServiceEntry) SetBoardMember(id string)

func (*ServiceEntry) SetClub

func (s *ServiceEntry) SetClub(id string)

func (*ServiceEntry) SetDescription

func (s *ServiceEntry) SetDescription(description string)

func (*ServiceEntry) SetMember

func (s *ServiceEntry) SetMember(id string)

func (*ServiceEntry) SetMinutes

func (s *ServiceEntry) SetMinutes(minutes int)

func (*ServiceEntry) SetServiceDate

func (s *ServiceEntry) SetServiceDate(dt types.DateTime)

func (*ServiceEntry) SetTitle

func (s *ServiceEntry) SetTitle(title string)

func (*ServiceEntry) Title

func (s *ServiceEntry) Title() string

type SimpleCount

type SimpleCount struct {
	Count int `json:"count" db:"count"`
}

func LoadCount

func LoadCount(app core.App, teamID string, season string) (SimpleCount, error)

type Team

type Team struct {
	core.BaseRecordProxy
}

Team RecordProxy for collection `teams`. Provides type-safe struct access to team records.

func (*Team) Admins

func (t *Team) Admins() []string

func (*Team) AgeGroup

func (t *Team) AgeGroup() string

func (*Team) BSMLeagueGroup

func (t *Team) BSMLeagueGroup() int

func (*Team) Club

func (t *Team) Club() string

func (*Team) CollectionName

func (t *Team) CollectionName() string

func (*Team) Description

func (t *Team) Description() string

func (*Team) HideSignupKey

func (t *Team) HideSignupKey()

func (*Team) ID

func (t *Team) ID() string

func (*Team) Name

func (t *Team) Name() string

func (*Team) SetAdmins

func (t *Team) SetAdmins(adminIDs []string)

func (*Team) SetAgeGroup

func (t *Team) SetAgeGroup(ageGroup string)

func (*Team) SetBSMLeagueGroup

func (t *Team) SetBSMLeagueGroup(id int)

func (*Team) SetClub

func (t *Team) SetClub(clubID string)

func (*Team) SetDescription

func (t *Team) SetDescription(desc string)

func (*Team) SetName

func (t *Team) SetName(name string)

func (*Team) SetSignupKey

func (t *Team) SetSignupKey(key string)

func (*Team) SignupKey

func (t *Team) SignupKey() string

func (*Team) UnhideSignupKey

func (t *Team) UnhideSignupKey()

type TeamWithSignupKey

type TeamWithSignupKey struct {
	Id        string `db:"id"`
	Club      string `db:"club"`
	SignupKey string `db:"signup_key"`
}

TeamWithSignupKey represents a reduced record with just the relevant fields.

type User

type User struct {
	core.BaseRecordProxy
}

User RecordProxy for collection `users`. Provides type-safe struct access to user records.

func GetAdminsForClub

func GetAdminsForClub(club Club, app core.App) ([]User, error)

func GetAdminsForTeam

func GetAdminsForTeam(team Team, app core.App) ([]User, error)

func GetUsersOnClub

func GetUsersOnClub(clubID string, app core.App) ([]User, error)

func GetUsersOnTeam

func GetUsersOnTeam(teamID string, app core.App) ([]User, error)

func (*User) AddClub

func (u *User) AddClub(clubID string)

func (*User) AddTeam

func (u *User) AddTeam(teamID string)

func (*User) Avatar

func (u *User) Avatar() string

func (*User) BSMID

func (u *User) BSMID() int

func (*User) Bats

func (u *User) Bats() string

func (*User) Birthday

func (u *User) Birthday() types.DateTime

func (*User) Clubs

func (u *User) Clubs() []string

func (*User) CollectionName

func (u *User) CollectionName() string

func (*User) DisplayName

func (u *User) DisplayName() string

func (*User) DisplayOnWebsite

func (u *User) DisplayOnWebsite() bool

func (*User) Email

func (u *User) Email() string

func (*User) EmailVisibility

func (u *User) EmailVisibility() bool

func (*User) FirstName

func (u *User) FirstName() string

func (*User) ID

func (u *User) ID() string

func (*User) Image

func (u *User) Image() string

func (*User) LastLogin

func (u *User) LastLogin() types.DateTime

func (*User) LastName

func (u *User) LastName() string

func (*User) Number

func (u *User) Number() string

func (*User) Position

func (u *User) Position() []string

func (*User) Scorer

func (u *User) Scorer() string

func (*User) SetAvatar

func (u *User) SetAvatar(filename string)

func (*User) SetBSMID

func (u *User) SetBSMID(id int)

func (*User) SetBats

func (u *User) SetBats(bats string)

func (*User) SetBirthday

func (u *User) SetBirthday(dt types.DateTime)

func (*User) SetClubs

func (u *User) SetClubs(clubIDs []string)

func (*User) SetDisplayName

func (u *User) SetDisplayName(name string)

func (*User) SetDisplayOnWebsite

func (u *User) SetDisplayOnWebsite(display bool)

func (*User) SetEmail

func (u *User) SetEmail(email string)

func (*User) SetEmailVisibility

func (u *User) SetEmailVisibility(visible bool)

func (*User) SetFirstName

func (u *User) SetFirstName(first string)
func (u *User) SetICalLink(link string)

SetICalLink sets the user's custom iCal link. Requires `WithCustomData` to be set.

func (*User) SetImage

func (u *User) SetImage(filename string)

func (*User) SetLastLogin

func (u *User) SetLastLogin(dt types.DateTime)

func (*User) SetLastName

func (u *User) SetLastName(last string)

func (*User) SetNumber

func (u *User) SetNumber(num string)

func (*User) SetPosition

func (u *User) SetPosition(pos []string)

func (*User) SetScorer

func (u *User) SetScorer(grade string)

func (*User) SetSignupKey

func (u *User) SetSignupKey(key string)

func (*User) SetTeams

func (u *User) SetTeams(teamIDs []string)

func (*User) SetThrows

func (u *User) SetThrows(throws string)

func (*User) SetUmpire

func (u *User) SetUmpire(grade string)

func (*User) SetUsername

func (u *User) SetUsername(username string)

func (*User) SetVerified

func (u *User) SetVerified(v bool)

func (*User) SignupKey

func (u *User) SignupKey() string

func (*User) Teams

func (u *User) Teams() []string

func (*User) Throws

func (u *User) Throws() string

func (*User) Umpire

func (u *User) Umpire() string

func (*User) Username

func (u *User) Username() string

func (*User) Verified

func (u *User) Verified() bool

type UserCommunityServiceData

type UserCommunityServiceData struct {
	User   User                       `json:"user"`
	Season int                        `json:"season"`
	Items  []UserCommunityServiceItem `json:"items"`
}

type UserCommunityServiceItem

type UserCommunityServiceItem struct {
	Club           Club           `json:"club"`
	CurrentMinutes int            `json:"current_minutes"`
	Entries        []ServiceEntry `json:"entries"`
}

type UserParticipationDTO

type UserParticipationDTO struct {
	ID          string `json:"id" db:"id"`
	FirstName   string `json:"first_name" db:"first_name"`
	LastName    string `json:"last_name" db:"last_name"`
	DisplayName string `json:"display_name" db:"display_name"`
}

type UserServiceApp

type UserServiceApp interface {
	FindRecordsByFilter(collectionModelOrIdentifier any, filter string, sort string, limit int, offset int, params ...dbx.Params) ([]*core.Record, error)
	Logger() *slog.Logger
	ExpandRecords(records []*core.Record, expands []string, optFetchFunc core.ExpandFetchFunc) map[string]error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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