storage

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExists = errors.New("already exists")
	ErrNotFound      = errors.New("not found")
)

Functions

This section is empty.

Types

type Color added in v0.2.0

type Color string
const (
	ColorBlue   Color = "blue"
	ColorRed    Color = "red"
	ColorYellow Color = "yellow"
	ColorGreen  Color = "green"
	ColorBlack  Color = "black"
	ColorPurple Color = "purple"
	ColorOrange Color = "orange"
	ColorPink   Color = "pink"
	ColorBronze Color = "bronze"
)

type DeviceTokenType added in v0.3.7

type DeviceTokenType string
const (
	DeviceTokenTypeSandbox    DeviceTokenType = "sdbx"
	DeviceTokenTypeProduction DeviceTokenType = "prod"
)

type Game added in v0.2.0

type Game struct {
	GameId      string
	SpectatorId string
	CreatedAt   time.Time
	ExpiresAt   time.Time
	Players     []*Player
}

type GameResults added in v0.3.2

type GameResults struct {
	Raw map[string]any
}

func (*GameResults) Scan added in v0.3.2

func (r *GameResults) Scan(value interface{}) error

func (*GameResults) Value added in v0.3.2

func (r *GameResults) Value() (driver.Value, error)

type Player added in v0.2.0

type Player struct {
	UserId   string
	PlayerId string
	Color    Color
}

type SearchUsers added in v0.3.15

type SearchUsers struct {
	Search         string
	ExcludedUserId string
	Limit          int
	Type           UserType
}

type SentNotification added in v0.3.1

type SentNotification struct {
	ActiveGames int `json:"ag"`
}

func (*SentNotification) Scan added in v0.3.1

func (sn *SentNotification) Scan(value interface{}) error

func (*SentNotification) Value added in v0.3.1

func (sn *SentNotification) Value() (driver.Value, error)

type SentNotificationUpdater added in v0.3.1

type SentNotificationUpdater func(ctx context.Context, state UserNotificationState) (UserNotificationState, error)

type Storage

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

func New

func New(db *sql.DB) (*Storage, error)

func (*Storage) CreateGame added in v0.2.0

func (s *Storage) CreateGame(ctx context.Context, game *Game) error

func (*Storage) GetActiveGames added in v0.3.2

func (s *Storage) GetActiveGames(ctx context.Context) ([]*Game, error)

func (*Storage) GetActiveUsers added in v0.3.1

func (s *Storage) GetActiveUsers(ctx context.Context, activityBuffer time.Duration) ([]string, error)

func (*Storage) GetGameByPlayerId added in v0.3.6

func (s *Storage) GetGameByPlayerId(ctx context.Context, playerId string) (*Game, error)

func (*Storage) GetGamesByUserId added in v0.2.0

func (s *Storage) GetGamesByUserId(ctx context.Context, userId string) ([]*Game, error)

func (*Storage) GetUserById

func (s *Storage) GetUserById(ctx context.Context, userId string) (*User, error)

func (*Storage) GetUserByNickname added in v0.2.0

func (s *Storage) GetUserByNickname(ctx context.Context, nickname string) (*User, error)

func (*Storage) SearchUsers added in v0.1.3

func (s *Storage) SearchUsers(ctx context.Context, req SearchUsers) ([]*User, error)

func (*Storage) UpdateDeviceToken added in v0.1.3

func (s *Storage) UpdateDeviceToken(ctx context.Context, userId string, deviceToken []byte, tokenType DeviceTokenType) error

func (*Storage) UpdateGameResults added in v0.3.2

func (s *Storage) UpdateGameResults(ctx context.Context, gameId string, results GameResults) error

func (*Storage) UpdateSentNotification added in v0.3.1

func (s *Storage) UpdateSentNotification(ctx context.Context, userId string, updater SentNotificationUpdater) error

func (*Storage) UpdateUser added in v0.0.4

func (s *Storage) UpdateUser(ctx context.Context, req UpdateUser) (*User, error)

func (*Storage) UpsertUser

func (s *Storage) UpsertUser(ctx context.Context, req UpsertUser) error

type UpdateUser added in v0.3.15

type UpdateUser struct {
	UserId   string
	Nickname string
	Color    Color
	Type     UserType
}

type UpsertUser added in v0.3.15

type UpsertUser struct {
	UserId   string
	Nickname string
	LastIp   string
	Color    Color
}

type User

type User struct {
	UserId          string
	Nickname        string
	Color           Color
	CreatedAt       time.Time
	DeviceToken     []byte
	DeviceTokenType DeviceTokenType
	LastIp          string
	Type            UserType
}

type UserNotificationState added in v0.3.7

type UserNotificationState struct {
	DeviceToken      []byte
	DeviceTokenType  DeviceTokenType
	SentNotification SentNotification
}

type UserType added in v0.3.15

type UserType string
const (
	UserTypeBlank  UserType = "blank"  // Just created users receive this type
	UserTypeActive UserType = "active" // Users that has changed their username and are ready to play
)

Jump to

Keyboard shortcuts

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