storage

package
v0.0.0-...-77e484d Latest Latest
Warning

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

Go to latest
Published: May 6, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound          = errors.New("Username not found")
	ErrIncorrectPassword = errors.New("Incorrect password")
)
View Source
var ErrNeedMoreGold = "Need more gold!"

Functions

func GetInstance

func GetInstance() *sql.DB

func InitDB

func InitDB(DSN string) error

Types

type GameStorage

type GameStorage struct {
	DB *sqlx.DB
}

func GetGameStorage

func GetGameStorage() *GameStorage

func (*GameStorage) AddUpgrade

func (s *GameStorage) AddUpgrade(upgrade *models.Upgrade) error

func (*GameStorage) BuyUpgrade

func (s *GameStorage) BuyUpgrade(userId int, upgradeId int) (err error)

func (*GameStorage) GetAllAvalibale

func (s *GameStorage) GetAllAvalibale(score int) ([]models.Upgrade, error)

func (*GameStorage) GetAllUpgrades

func (s *GameStorage) GetAllUpgrades() ([]models.Upgrade, error)

func (*GameStorage) GetUpgradeById

func (s *GameStorage) GetUpgradeById(upgradeID int) (upgrade models.Upgrade, err error)

type GameStorageI

type GameStorageI interface {
	AddUpgrade(*models.Upgrade) error

	GetAllUpgrades() ([]models.Upgrade, error)
	GetUpgradeById(int) (models.Upgrade, error)
	BuyUpgrade(userId int, upgradeId int) error
}

type UserStorage

type UserStorage struct {
	DB *sqlx.DB
}

func GetUserStorage

func GetUserStorage() *UserStorage

func (*UserStorage) Add

func (s *UserStorage) Add(user *models.User) error

func (*UserStorage) CheckExists

func (s *UserStorage) CheckExists(user models.User) (usernameExist bool, emailExist bool, err error)

func (*UserStorage) GetAll

func (s *UserStorage) GetAll() (users []models.User, err error)

func (*UserStorage) GetAllWithOptions

func (s *UserStorage) GetAllWithOptions(limit int, offset int) ([]models.User, error)

func (*UserStorage) GetByEmail

func (s *UserStorage) GetByEmail(email string) (user models.User, has bool, err error)

func (*UserStorage) GetByID

func (s *UserStorage) GetByID(uid int) (user models.User, has bool, err error)

func (*UserStorage) GetByUsername

func (s *UserStorage) GetByUsername(username string) (user models.User, has bool, err error)

func (*UserStorage) Login

func (s *UserStorage) Login(username string, password string) (models.User, error)

func (*UserStorage) UpdateEmail

func (s *UserStorage) UpdateEmail(id int, newEmail string) error

func (*UserStorage) UpdatePassword

func (s *UserStorage) UpdatePassword(id int, newPassword string) error

func (*UserStorage) UpdateScore

func (s *UserStorage) UpdateScore(id int, newScore int) error

func (*UserStorage) UpdateUsername

func (s *UserStorage) UpdateUsername(id int, newUsername string) error

type UserStorageI

type UserStorageI interface {
	Add(*models.User) error

	GetAll() ([]models.User, error)
	GetAllWithOptions(limit int, offset int) ([]models.User, error)

	GetByID(id int) (models.User, bool, error)
	GetByEmail(email string) (models.User, bool, error)
	GetByUsername(username string) (models.User, bool, error)

	UpdateUsername(uid int, newUsername string) error
	UpdateEmail(uid int, newEmail string) error
	UpdatePassword(uid int, newEmail string) error
	UpdateScore(uid int, newScore int) error

	CheckExists(models.User) (usernameExist bool, emailExist bool, err error)
	Login(username string, password string) (models.User, error)
}

Jump to

Keyboard shortcuts

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