shop

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: 19 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 shop endpoints.

func NewHandler

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

NewHandler returns a new shop handler.

func (*Handler) Create

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

Create creates a new shop and saves it.

func (*Handler) Delete

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

Delete removes a shop.

func (*Handler) Get

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

Get lists all the shops.

func (*Handler) GetByID

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

GetByID lists the shop 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 shop with the given id.

type Location

type Location struct {
	ShopID  string `json:"shop_id,omitempty" db:"shop_id"`
	Country string `json:"country,omitempty" validate:"required"`
	State   string `json:"state,omitempty"`
	ZipCode string `json:"zip_code,omitempty" db:"zip_code"`
	City    string `json:"city,omitempty" validate:"required"`
	Address string `json:"address,omitempty" validate:"required"`
}

Location of the shop.

type Service

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

Service provides shop operations.

func NewService

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

NewService returns a new shop service.

type Shop

type Shop struct {
	ID        string            `json:"id,omitempty"`
	Name      string            `json:"name,omitempty" validate:"required"`
	Location  Location          `json:"location,omitempty"`
	Reviews   []review.Review   `json:"reviews,omitempty"`
	Products  []product.Product `json:"products,omitempty"`
	CreatedAt time.Time         `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt zero.Time         `json:"updated_at,omitempty" db:"updated_at"`
}

Shop represents a market with its name and location. Each shop has multiple reviews and products.

type UpdateShop

type UpdateShop struct {
	Name string `json:"name,omitempty" validate:"required"`
}

UpdateShop is the structure used to update shops.

Jump to

Keyboard shortcuts

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