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 ¶
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) 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.
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.
Click to show internal directories.
Click to hide internal directories.