Documentation ¶
Index ¶
- Variables
- func ValidateEmail(v *validator.Validator, email string)
- func ValidateFilters(v *validator.Validator, f Filters)
- func ValidatePasswordPlainText(v *validator.Validator, password string)
- func ValidateUser(v *validator.Validator, user User)
- type Filters
- type Furniture
- type FurnitureRepository
- type Metadata
- type Repositories
- type User
- type UserRepository
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRecordNotFound is a custom error that is returned when looking // for a specific record that is not in the database. ErrRecordNotFound = errors.New("record not found") // ErrEditConflict is a custom error that is returned when two or more // users try to access the same record concurrently. ErrEditConflict = errors.New("edit conflict") // ErrDuplicateEmail is a custom error that is returned when there // is a duplicate email in the database. ErrDuplicateEmail = errors.New("duplicate email") )
Functions ¶
func ValidateEmail ¶
func ValidateFilters ¶
func ValidateUser ¶
Types ¶
type Furniture ¶
type Furniture struct { FurnitureID int64 Name string Description string Price float64 Stock int BannerURL string ImageURLs []string Category string Rating float32 Version int }
Furniture is a struct that holds information about a specific furniture.
type FurnitureRepository ¶
FurnitureRepository is a type which wraps around a sql.DB connection pool and provide methods for creating and managing furniture to and from the database.
func (FurnitureRepository) GetAll ¶
func (f FurnitureRepository) GetAll(name, category string, price float64, filters Filters) ([]Furniture, float32, Metadata, error)
GetAll returns list of furniture, rating and metadata from the database matching the provided parameters.
func (FurnitureRepository) GetByID ¶
func (f FurnitureRepository) GetByID(id int64) (Furniture, error)
GetByID retrieve a specific furniture record from the database given the id.
func (FurnitureRepository) Insert ¶
func (f FurnitureRepository) Insert(furniture *Furniture) error
Insert a furniture record to the database.
type Metadata ¶
type Metadata struct { CurrentPage int `json:"current_page,omitempty"` PageSize int `json:"page_size,omitempty"` FirstPage int `json:"first_page,omitempty"` LastPage int `json:"last_page,omitempty"` TotalRecords int `json:"total_records,omitempty"` }
Metadata is a struct that is used to holds pagination metadata.
type Repositories ¶
type Repositories struct { Users UserRepository Furniture FurnitureRepository }
Repositories is a container that holds all the database repositories for this project.
func NewRepositories ¶
func NewRepositories(db *sql.DB) Repositories
NewRepositories returns a Repositories which contains all initialized repositories for interacting with the database. for the project.
type User ¶
type User struct { UserID int64 Name string Email string Password password Address sql.NullString PhoneNumber sql.NullString // Differentiate between types of User (admin, customer) Role string CreatedAt time.Time }
User is a struct that holds information about a specific user.
type UserRepository ¶
UserRepository is a type which wraps around a sql.DB connection pool and provide methods for creating and managing users to and from the database.
func (UserRepository) GetByEmail ¶
func (u UserRepository) GetByEmail(email string) (User, error)
GetByEmail retrieve a specific User from the database given the email address.
func (UserRepository) GetByID ¶
func (u UserRepository) GetByID(userID int64) (User, error)
GetByID retrieve a specific User from the database given the userID.
func (UserRepository) Insert ¶
func (u UserRepository) Insert(user *User) error
Insert a user record to the database.