postgres

package
v0.0.0-...-015e340 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 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 {
	// contains filtered or unexported fields
}

func NewFranchiseModel

func NewFranchiseModel(db *sql.DB) *FranchiseModel

func (*FranchiseModel) All

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

func (*FranchiseModel) Insert

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

type GameModel

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

GameModel wraps an sql.DB connection pool.

func NewGameModel

func NewGameModel(db *sql.DB) *GameModel

func (*GameModel) AllForUser

func (m *GameModel) AllForUser(userID string) ([]*models.Game, error)

AllForUser fetches all games for the given user from the database and returns them, or an error if such occurred.

func (*GameModel) ChangeGameProgress

func (m *GameModel) ChangeGameProgress(userID, gameID string, progress *models.GameProgress) error

func (*GameModel) ChangeGameStatus

func (m *GameModel) ChangeGameStatus(userID, gameID string, status models.Status) error

func (*GameModel) DeleteGame

func (m *GameModel) DeleteGame(userID, gameID string) error

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 UserModel

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

UserModel wraps a DB connection pool.

func NewUserModel

func NewUserModel(db *sql.DB) *UserModel

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