review

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: 17 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 reviews endpoints.

func NewHandler

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

NewHandler returns a new review handler.

func (*Handler) Create

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

Create creates a new review and saves it.

func (*Handler) Delete

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

Delete removes a review.

func (*Handler) Get

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

Get lists all the reviews.

func (*Handler) GetByID

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

GetByID lists the review with the id requested.

type Review

type Review struct {
	ID        zero.String `json:"id,omitempty"`
	Stars     zero.Int    `json:"stars,omitempty" validate:"min=0,max=5"`
	Comment   zero.String `json:"comment,omitempty"`
	UserID    zero.String `json:"user_id,omitempty" db:"user_id" validate:"required"`
	ProductID zero.String `json:"product_id,omitempty" db:"product_id" validate:"required_without=ShopID"`
	ShopID    zero.String `json:"shop_id,omitempty" db:"shop_id" validate:"required_without=ProductID"`
	CreatedAt zero.Time   `json:"created_at,omitempty" db:"created_at"`
}

Review represents users critics over a shop or product.

type Service

type Service interface {
	Create(ctx context.Context, r Review) error
	Delete(ctx context.Context, id string) error
	Get(ctx context.Context, params params.Query) ([]Review, error)
	GetByID(ctx context.Context, id string) (Review, error)
}

Service provides review operations.

func NewService

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

NewService returns a new review service.

Jump to

Keyboard shortcuts

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