product

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

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler handles product endpoints.

func NewHandler

func NewHandler(service Service, cache *memcache.Client) Handler

NewHandler returns a new product handler.

func (*Handler) Create

func (h *Handler) Create() http.HandlerFunc

Create creates a new product and saves it.

func (*Handler) Delete

func (h *Handler) Delete() http.HandlerFunc

Delete removes a product.

func (*Handler) Get

func (h *Handler) Get() http.HandlerFunc

Get lists all the products.

func (*Handler) GetByID

func (h *Handler) GetByID() http.HandlerFunc

GetByID lists the product with the id requested.

func (*Handler) Search

func (h *Handler) Search() http.HandlerFunc

Search looks for the products with the given value.

func (*Handler) Update

func (h *Handler) Update() http.HandlerFunc

Update updates the product with the given id.

type Product

type Product struct {
	ID          zero.String `json:"id,omitempty"`
	ShopID      zero.String `json:"shop_id,omitempty" db:"shop_id" validate:"required"`
	Stock       zero.Int    `json:"stock,omitempty"`
	Brand       zero.String `json:"brand,omitempty" validate:"required"`
	Category    zero.String `json:"category,omitempty" validate:"required"`
	Type        zero.String `json:"type,omitempty" validate:"required"`
	Description zero.String `json:"description,omitempty"`
	// 1000 = 1kg
	Weight    zero.Int        `json:"weight,omitempty" validate:"required,min=1"`
	Discount  zero.Int        `json:"discount,omitempty" validate:"min=0"`
	Taxes     zero.Int        `json:"taxes,omitempty" validate:"min=0"`
	Subtotal  zero.Int        `json:"subtotal,omitempty" validate:"required"`
	Total     zero.Int        `json:"total,omitempty" validate:"min=0"`
	Reviews   []review.Review `json:"reviews,omitempty"`
	CreatedAt zero.Time       `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt zero.Time       `json:"updated_at,omitempty" db:"updated_at"`
}

Product represents a market commodity.

Amounts to be provided in a currency’s smallest unit. 100 = 1 USD.

type Service

type Service interface {
	Create(ctx context.Context, p Product) error
	Delete(ctx context.Context, id string) error
	Get(ctx context.Context, params params.Query) ([]Product, error)
	GetByID(ctx context.Context, id string) (Product, error)
	Search(ctx context.Context, query string) ([]Product, error)
	Update(ctx context.Context, id string, p UpdateProduct) error
}

Service provides product operations.

func NewService

func NewService(db *sqlx.DB, mc *memcache.Client) Service

NewService returns a new product service.

type UpdateProduct

type UpdateProduct struct {
	Stock       zero.Int    `json:"stock,omitempty"`
	Brand       zero.String `json:"brand,omitempty" validate:"required"`
	Category    zero.String `json:"category,omitempty" validate:"required"`
	Type        zero.String `json:"type,omitempty" validate:"required"`
	Description zero.String `json:"description,omitempty"`
	Weight      zero.Int    `json:"weight,omitempty" validate:"required,min=1"`
	Discount    zero.Int    `json:"discount,omitempty" validate:"min=0"`
	Taxes       zero.Int    `json:"taxes,omitempty" validate:"min=0"`
	Subtotal    zero.Int    `json:"subtotal,omitempty" validate:"required"`
	Total       zero.Int    `json:"total,omitempty" validate:"min=0"`
}

UpdateProduct is the structure used to update products.

Jump to

Keyboard shortcuts

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