data

package
v0.0.0-...-8ec0a96 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 ValidateEmail(v *validator.Validator, email string)

func ValidateFilters

func ValidateFilters(v *validator.Validator, f Filters)

func ValidatePasswordPlainText

func ValidatePasswordPlainText(v *validator.Validator, password string)

func ValidateUser

func ValidateUser(v *validator.Validator, user User)

Types

type Filters

type Filters struct {
	Page         int
	PageSize     int
	Sort         string
	SortSafeList []string
}

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

type FurnitureRepository struct {
	DB *sql.DB
}

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

type UserRepository struct {
	DB *sql.DB
}

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.

Jump to

Keyboard shortcuts

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