inventory

package
v0.0.0-...-7c5988b Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCreateReviewNoProduct = errors.New("cannot find product to create review")

ErrCreateReviewNoProduct is returned when a product review cannot be created because a product is not found.

Functions

This section is empty.

Types

type CreateProductParams

type CreateProductParams struct {
	ID          string
	Name        string
	Description string
	Price       int
}

CreateProductParams used by CreateProduct.

type CreateProductReviewDBParams

type CreateProductReviewDBParams struct {
	ID string
	CreateProductReviewParams
}

CreateProductReviewParams is used when creating the review of a product in the database.

type CreateProductReviewParams

type CreateProductReviewParams struct {
	ProductID   string
	ReviewerID  string
	Score       int32
	Title       string
	Description string
}

CreateProductReviewParams is used when creating the review of a product.

type DB

type DB interface {
	// CreateProduct creates a new product.
	CreateProduct(ctx context.Context, params CreateProductParams) error

	// UpdateProduct updates an existing product.
	UpdateProduct(ctx context.Context, params UpdateProductParams) error

	// GetProduct returns a product.
	GetProduct(ctx context.Context, id string) (*Product, error)

	// SearchProducts returns a list of products.
	SearchProducts(ctx context.Context, params SearchProductsParams) (*SearchProductsResponse, error)

	// DeleteProduct deletes a product.
	DeleteProduct(ctx context.Context, id string) error

	// CreateProductReview for a given product.
	CreateProductReview(ctx context.Context, params CreateProductReviewDBParams) error

	// UpdateProductReview for a given product.
	UpdateProductReview(ctx context.Context, params UpdateProductReviewParams) error

	// GetProductReview gets a specific review.
	GetProductReview(ctx context.Context, id string) (*ProductReview, error)

	// GetProductReviews gets reviews for a given product or from a given user.
	GetProductReviews(ctx context.Context, params ProductReviewsParams) (*ProductReviewsResponse, error)

	// DeleteProductReview deletes a review.
	DeleteProductReview(ctx context.Context, id string) error
}

DB layer.

type Pagination

type Pagination struct {
	// Limit is the maximum number of results to return on this page.
	Limit int

	// Offset is the number of results to skip from the beginning of the results.
	// Typically: (page number - 1) * limit.
	Offset int
}

Pagination is used to paginate results.

Usage:

Pagination{
	Limit: limit,
	Offset: (page - 1) * limit
}

func (*Pagination) Validate

func (p *Pagination) Validate() error

Validate pagination.

type Product

type Product struct {
	ID          string
	Name        string
	Description string
	Price       int
	CreatedAt   time.Time
	ModifiedAt  time.Time
}

Product on the catalog.

type ProductReview

type ProductReview struct {
	ID          string
	ProductID   string
	ReviewerID  string
	Score       int32
	Title       string
	Description string
	CreatedAt   time.Time
	ModifiedAt  time.Time
}

ProductReview of a product.

type ProductReviewsParams

type ProductReviewsParams struct {
	ProductID  string
	ReviewerID string
	Pagination Pagination
}

ProductReviewsParams is used to get a list of reviews.

type ProductReviewsResponse

type ProductReviewsResponse struct {
	Reviews []*ProductReview
	Total   int
}

ProductReviewsResponse is the response from GetProductReviews.

type SearchProductsParams

type SearchProductsParams struct {
	QueryString string
	MinPrice    int
	MaxPrice    int
	Pagination  Pagination
}

SearchProductsParams used by SearchProducts.

type SearchProductsResponse

type SearchProductsResponse struct {
	Items []*Product
	Total int32
}

SearchProductsResponse from SearchProducts.

type Service

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

Service for the API.

func NewService

func NewService(db DB) *Service

NewService creates an API service.

func (*Service) CreateProduct

func (s *Service) CreateProduct(ctx context.Context, params CreateProductParams) (err error)

CreateProduct creates a new product.

func (*Service) CreateProductReview

func (s *Service) CreateProductReview(ctx context.Context, params CreateProductReviewParams) (id string, err error)

CreateProductReview of a product.

func (*Service) DeleteProduct

func (s *Service) DeleteProduct(ctx context.Context, id string) (err error)

DeleteProduct deletes a product.

func (*Service) DeleteProductReview

func (s *Service) DeleteProductReview(ctx context.Context, id string) error

DeleteProductReview of a product.

func (*Service) GetProduct

func (s *Service) GetProduct(ctx context.Context, id string) (*Product, error)

GetProduct returns a product.

func (*Service) GetProductReview

func (s *Service) GetProductReview(ctx context.Context, id string) (*ProductReview, error)

GetProductReview gets a product review.

func (*Service) GetProductReviews

func (s *Service) GetProductReviews(ctx context.Context, params ProductReviewsParams) (*ProductReviewsResponse, error)

GetProductReviews gets a list of reviews.

func (*Service) SearchProducts

func (s *Service) SearchProducts(ctx context.Context, params SearchProductsParams) (*SearchProductsResponse, error)

SearchProducts returns a list of products.

func (*Service) UpdateProduct

func (s *Service) UpdateProduct(ctx context.Context, params UpdateProductParams) (err error)

UpdateProduct creates a new product.

func (*Service) UpdateProductReview

func (s *Service) UpdateProductReview(ctx context.Context, params UpdateProductReviewParams) error

UpdateProductReview of a product.

type UpdateProductParams

type UpdateProductParams struct {
	ID          string
	Name        *string
	Description *string
	Price       *int
}

UpdateProductParams used by UpdateProduct.

type UpdateProductReviewParams

type UpdateProductReviewParams struct {
	ID          string
	Score       *int32
	Title       *string
	Description *string
}

UpdateProductReviewParams to use when updating an existing review.

type ValidationError

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

ValidationError is returned when there is an invalid parameter received.

func (ValidationError) Error

func (e ValidationError) Error() string

Jump to

Keyboard shortcuts

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