game

package
v0.0.0-...-222756a Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

type Game struct {
	ID           primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	PointsGained int                `json:"points_gained,omitempty" bson:"points_gained,omitempty"`
	WinStatus    int8               `json:"win_status,omitempty" bson:"win_status,omitempty"`
	GameType     int8               `json:"game_type,omitempty" bson:"game_type,omitempty"`
	Created      time.Time          `json:"created,omitempty" bson:"created,omitempty"`
	UserID       primitive.ObjectID `json:"user_id,omitempty" bson:"user_id,omitempty"`
}

type GamesStatistics

type GamesStatistics struct {
	GroupByDay []struct {
		GroupDate   string `json:"date" bson:"date"`
		GamesPlayed int64  `json:"games_played" bson:"games_played"`
	} `json:"group_by_day" bson:"group_by_day"`
	WithGameType []struct {
		GameDate    string `json:"date" bson:"date"`
		GameType    int8   `json:"game_type" bson:"game_type"`
		GamesPlayed int64  `json:"games_played" bson:"games_played"`
	} `json:"with_game_type" bson:"with_game_type"`
}

type Handler

type Handler struct {
	Logger      *log.Logger
	GameService Service
}

func (*Handler) GetAllGames

func (h *Handler) GetAllGames(w http.ResponseWriter, r *http.Request) error

func (*Handler) GetGame

func (h *Handler) GetGame(w http.ResponseWriter, r *http.Request) error

func (*Handler) GetGamesByPlayer

func (h *Handler) GetGamesByPlayer(w http.ResponseWriter, r *http.Request) error

func (*Handler) GetGamesStatistics

func (h *Handler) GetGamesStatistics(w http.ResponseWriter, r *http.Request) error

func (*Handler) Register

func (h *Handler) Register(router *http.ServeMux)

type Service

type Service interface {
	GetById(ctx context.Context, id string) (Game, error)
	GetByPlayer(ctx context.Context, uuid string, limit, page int64) ([]Game, error)
	GetAll(ctx context.Context, limit, page int64) ([]Game, error)
	GetGamesStatistics(ctx context.Context, userId string, startDate, endDate time.Time) ([]GamesStatistics, error)
}

func NewService

func NewService(storage Storage, logger *log.Logger) (Service, error)

type Storage

type Storage interface {
	FindById(ctx context.Context, id string) (Game, error)
	FindByPlayer(ctx context.Context, uuid string, limit, page int64) ([]Game, error)
	FindAll(ctx context.Context, limit, page int64) ([]Game, error)
	AggregateGamesStatistics(ctx context.Context, uuid string, startDate, endDate time.Time) ([]GamesStatistics, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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