shop

package module
v0.0.0-...-f33abe1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 8 Imported by: 0

README

shop

For e-commerce.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("shop: not found")
	ErrConflict = errors.New("shop: conflict on id")
)

Functions

This section is empty.

Types

type Handler

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

Handler implements http.Handler and provides an interface for API requests to interact with the ProductService.

func NewHandler

func NewHandler(s Service, l *slog.Logger) *Handler

NewHandler returns a new Handler.

func (*Handler) CreateProduct

func (h *Handler) CreateProduct(w http.ResponseWriter, r *http.Request)

POST /products

func (*Handler) DeleteProduct

func (h *Handler) DeleteProduct(w http.ResponseWriter, r *http.Request)

Delete a product identified in the URL. DELETE /products/{productID}

func (*Handler) GetProduct

func (h *Handler) GetProduct(w http.ResponseWriter, r *http.Request)

GetProduct will parse and respond to an API request for a specific product defined by its {productID} in the request URL. GET /products/{productID}

func (*Handler) ListProducts

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

ListProducts returns a subset of products defined by the filters in the URL. GET /products

func (*Handler) UpdateProduct

func (h *Handler) UpdateProduct(w http.ResponseWriter, r *http.Request)

Update a subset of a products attributes. The product is identified by its {productID} in the URL. PATCH /products/{productID}

type Price

type Price float64

func (Price) String

func (p Price) String() string

type Product

type Product struct {
	ID          string `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Price       Price  `json:"price,omitempty"`
}

Product defines a single product, represented by its unique ID.

type ProductFilter

type ProductFilter struct{}

ProductFilter defines the attributes a user can use to filter/limit a subset of results in a request for a list of products.

type ProductUpdate

type ProductUpdate struct{}

ProductUpdate defines the attributes that can be updated in a PATCH request.

type Service

type Service interface {
	CreateProduct(ctx context.Context, p Product) (Product, error)
	GetProduct(ctx context.Context, id string) (Product, error)
	ListProducts(ctx context.Context, f ProductFilter) ([]Product, error)
	UpdateProduct(ctx context.Context, id string, upd ProductUpdate) (Product, error)
	DeleteProduct(ctx context.Context, id string) error
}

Service

Jump to

Keyboard shortcuts

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