leaderboard

package
v0.0.0-...-a0fcb3e Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AggregationModeInc = "INC"
	AggregationModeMax = "MAX"
	AggregationModeMin = "MIN"

	OrderingAsc  = "ASC"
	OrderingDesc = "DESC"
)
View Source
const (
	MaxLimitNumber = 500
	MinLimitNumber = 1
	MinPageNumber  = 0
)

Variables

View Source
var (
	ErrValidationError        = errors.New("validation error")
	ErrInvalidName            = errors.New("invalid name")
	ErrInvalidGameID          = errors.New("invalid game id")
	ErrInvalidStartDate       = errors.New("invalid start date")
	ErrInvalidAggregationMode = errors.New("invalid aggregation mode")
	ErrInvalidOrdering        = errors.New("invalid ordering")
	ErrEndDateBeforeStartDate = errors.New("end date must be after the start date")

	ErrInvalidLeaderboardID = errors.New("invalid leaderboard id")
	ErrLeaderboardNotFound  = errors.New("leaderboard not found")
)
View Source
var (
	AggregationModes = []string{
		AggregationModeInc,
		AggregationModeMax,
		AggregationModeMin,
	}
	OrderingModes = []string{
		OrderingAsc,
		OrderingDesc,
	}
)
View Source
var (
	ErrLeaderboardClosed  = errors.New("leaderboard closed")
	ErrInvalidPageNumber  = errors.New("invalid page number")
	ErrInvalidLimitNumber = errors.New("invalid limit number")
)

Functions

This section is empty.

Types

type CreateFunc

type CreateFunc func(ctx context.Context, data NewLeaderboardData) (Leaderboard, error)

Create a leaderboard and return it's id

func BuildCreateFunc

func BuildCreateFunc(storageCreateFunc StorageCreateLeaderboardFunc) CreateFunc

type GetByIDAndGameIDFunc

type GetByIDAndGameIDFunc func(ctx context.Context, id, gameID string) (Leaderboard, error)

Get a leaderboard by it's id and game id

func BuildGetByIDAndGameIDFunc

func BuildGetByIDAndGameIDFunc(storageGetFunc StorageGetLeaderboardByIDAndGameIDFunc) GetByIDAndGameIDFunc

type Leaderboard

type Leaderboard struct {
	CreatedAt       time.Time // Time that the leaderboard was created
	UpdatedAt       time.Time // Last time that the leaderboard info was updated
	DeletedAt       time.Time // Time that the leaderboard was deleted
	ID              string    // Leaderboard's ID
	GameID          string    // The ID from the game that is responsible for the leaderboard
	Name            string    // Leaderboard's name
	Description     string    // Leaderboard's description
	StartAt         time.Time // Time that the leaderboard should start working
	EndAt           time.Time // Time that the leaderboard will be closed for new updates
	AggregationMode string    // Data aggregation mode
	Ordering        string    // Leaderboard ranking order
}

func (Leaderboard) Closed

func (l Leaderboard) Closed() bool

type NewLeaderboardData

type NewLeaderboardData struct {
	GameID          string    // The ID from the game that is responsible for the leaderboard
	Name            string    // Leaderboard's name
	Description     string    // Leaderboard's description
	StartAt         time.Time // Time that the leaderboard should start working
	EndAt           time.Time // Time that the leaderboard will be closed for new updates
	AggregationMode string    // Data aggregation mode
	Ordering        string    // Leaderboard ranking order
}

type Rank

type Rank struct {
	LeaderboardID string
	PlayerID      string
	Position      int64
	Value         float64
}

type RankingFunc

type RankingFunc func(ctx context.Context, leaderboard Leaderboard, page, limit int64) ([]Rank, error)

Leaderboard ranking paginated

func BuildRankingFunc

func BuildRankingFunc(getRankingFunc StorageGetRankingFunc) RankingFunc

type SoftDeleteFunc

type SoftDeleteFunc func(ctx context.Context, id, gameID string) error

Soft Delete a leaderboard

func BuildSoftDeleteFunc

func BuildSoftDeleteFunc(storageSoftDeleteFunc StorageSoftDeleteLeaderboardFunc) SoftDeleteFunc

type StorageCreateLeaderboardFunc

type StorageCreateLeaderboardFunc func(ctx context.Context, data NewLeaderboardData) (Leaderboard, error)

Storage function that is responsible for creating the leaderboard

type StorageGetLeaderboardByIDAndGameIDFunc

type StorageGetLeaderboardByIDAndGameIDFunc func(ctx context.Context, id, gameID string) (Leaderboard, error)

Storage function that returns a leaderboard by it's id and game id

type StorageGetRankingFunc

type StorageGetRankingFunc func(ctx context.Context, leaderboardID, ordering string, page, limit int64) ([]Rank, error)

Get the leaderboard ranking paginated

type StorageSoftDeleteLeaderboardFunc

type StorageSoftDeleteLeaderboardFunc func(ctx context.Context, id, gameID string) error

Storage function that soft delete a leaderboard

type StorageUpsertPlayerRankValueFunc

type StorageUpsertPlayerRankValueFunc func(ctx context.Context, leaderboard Leaderboard, playerID string, value float64) error

Updates the player's rank value using the value provided

type UpsertPlayerRankFunc

type UpsertPlayerRankFunc func(ctx context.Context, leaderboard Leaderboard, playerID string, value float64) error

Set or update the player's rank

func BuildUpsertPlayerRankFunc

func BuildUpsertPlayerRankFunc(upsertPlayerRankValueFunc StorageUpsertPlayerRankValueFunc) UpsertPlayerRankFunc

Jump to

Keyboard shortcuts

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