postgres

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNameAlreadyExists is the error that is returned, when a game with that name already exists in the database
	ErrNameAlreadyExists = errors.New("model with that name already exists in the database")
	// ErrNoRecord is returned when a game with that criteria does not exist in the database
	ErrNoRecord = errors.New("such model does not exist in the database")
)
View Source
var (
	// ErrEmailAlreadyExists is returned when a user with the same email already exists in the database
	ErrEmailAlreadyExists = errors.New("user with the same email already exists")
	// ErrUsernameAlreadyExists is returned when a user with the same username already exists in the database
	ErrUsernameAlreadyExists = errors.New("user with the same username already exists")
	// ErrWrongPassword is returned when the given password does not match the user password
	ErrWrongPassword = errors.New("the given password does not match the user password")
)

Functions

This section is empty.

Types

type FranchiseModel

type FranchiseModel struct {
	DB *sql.DB
}

func (*FranchiseModel) All

func (m *FranchiseModel) All() ([]*models.Franchise, error)

func (*FranchiseModel) Insert

func (m *FranchiseModel) Insert(franchise *models.Franchise) (*models.Franchise, error)

type GameModel

type GameModel struct {
	DB *sql.DB
}

GameModel wraps an sql.DB connection pool.

func (*GameModel) All

func (m *GameModel) All() ([]*models.Game, error)

All fetches all games from the database and returns them, or an error if such occurred.

func (*GameModel) Get

func (m *GameModel) Get(id string) (*models.Game, error)

Get fetches a Game by ID and returns that or an error if such occurred. If game with that ID is not present in the database, an ErrNoRecord is returned.

func (*GameModel) Insert

func (m *GameModel) Insert(game *models.Game) (*models.Game, error)

Insert inserts the passed Game into the database. It returns the ID of the created game, or error if such occurred. If a game with the same name already exists, an ErrNameAlreadyExists is returned

type UserGamesModel

type UserGamesModel struct {
	DB *sql.DB
}

func (*UserGamesModel) ChangeGameProgress

func (m *UserGamesModel) ChangeGameProgress(userID, userGameID string, progress *models.UserGameProgress) error

func (*UserGamesModel) ChangeGameStatus

func (m *UserGamesModel) ChangeGameStatus(userID, userGameID string, status models.Status) error

func (*UserGamesModel) DeleteUserGame

func (m *UserGamesModel) DeleteUserGame(userGameID string) error

func (*UserGamesModel) GetAvailableGamesFor

func (m *UserGamesModel) GetAvailableGamesFor(userID string) ([]*models.Game, error)

func (*UserGamesModel) GetUserGames

func (m *UserGamesModel) GetUserGames(userID string) ([]*models.UserGame, error)

func (*UserGamesModel) GetUserGamesGrouped

func (m *UserGamesModel) GetUserGamesGrouped(userID string) (map[models.Status][]*models.UserGame, error)

func (*UserGamesModel) LinkGameToUser

func (m *UserGamesModel) LinkGameToUser(userID, gameID string, progress *models.UserGameProgress) error

type UserModel

type UserModel struct {
	DB *sql.DB
}

UserModel wraps a DB connection pool.

func (*UserModel) AssociateTokenWithUser

func (m *UserModel) AssociateTokenWithUser(userID, token string) error

AssociateTokenWithUser associated the given token with the given userID

func (*UserModel) Authenticate

func (m *UserModel) Authenticate(email, password string) (*models.User, error)

Authenticate authenticates a use with these credentials and returns the user or an error if such occurred.

func (*UserModel) GetUserByToken

func (m *UserModel) GetUserByToken(token string) (*models.User, error)

GetUserByToken returns the user, associated with the token passed to the method

func (*UserModel) Insert

func (m *UserModel) Insert(user *models.User) (*models.User, error)

Insert inserts a new user with the given parameters into the database and return the created user ot an error if such occurred.

func (*UserModel) InvalidateToken

func (m *UserModel) InvalidateToken(userID, token string) error

InvalidateToken deleted the token from the database, making it invalid

Jump to

Keyboard shortcuts

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