Documentation
¶
Index ¶
- Variables
- type CreateProductParams
- type CreateProductReviewDBParams
- type CreateProductReviewParams
- type DB
- type Pagination
- type Product
- type ProductReview
- type ProductReviewsParams
- type ProductReviewsResponse
- type SearchProductsParams
- type SearchProductsResponse
- type Service
- func (s *Service) CreateProduct(ctx context.Context, params CreateProductParams) (err error)
- func (s *Service) CreateProductReview(ctx context.Context, params CreateProductReviewParams) (id string, err error)
- func (s *Service) DeleteProduct(ctx context.Context, id string) (err error)
- func (s *Service) DeleteProductReview(ctx context.Context, id string) error
- func (s *Service) GetProduct(ctx context.Context, id string) (*Product, error)
- func (s *Service) GetProductReview(ctx context.Context, id string) (*ProductReview, error)
- func (s *Service) GetProductReviews(ctx context.Context, params ProductReviewsParams) (*ProductReviewsResponse, error)
- func (s *Service) SearchProducts(ctx context.Context, params SearchProductsParams) (*SearchProductsResponse, error)
- func (s *Service) UpdateProduct(ctx context.Context, params UpdateProductParams) (err error)
- func (s *Service) UpdateProductReview(ctx context.Context, params UpdateProductReviewParams) error
- type UpdateProductParams
- type UpdateProductReviewParams
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 }
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 ¶
SearchProductsResponse from SearchProducts.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service for the API.
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 ¶
DeleteProduct deletes a product.
func (*Service) DeleteProductReview ¶
DeleteProductReview of a product.
func (*Service) GetProduct ¶
GetProduct returns a product.
func (*Service) GetProductReview ¶
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 ¶
UpdateProductParams used by UpdateProduct.
type UpdateProductReviewParams ¶
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