Documentation
¶
Index ¶
- type ProductService
- func (p *ProductService) CreateProduct(ctx context.Context, name string, price float64, stock int) (int, error)
- func (p *ProductService) GetProduct(ctx context.Context, id int) (*store.Product, error)
- func (p *ProductService) GetProducts(ctx context.Context, name string) ([]*store.Product, error)
- func (p *ProductService) UpdateProduct(ctx context.Context, id int, name string, price float64, stock int) error
- func (p *ProductService) UpdateProductStock(ctx context.Context, id int, stock int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ProductService ¶
type ProductService struct {
// contains filtered or unexported fields
}
func NewProductService ¶
func NewProductService(db *store.Store, logger *slog.Logger) *ProductService
NewProductService returns a ProductService with the given db and logger. The product service can be used to interact with the database through the Store struct. The service also has validation for the methods so it's better to use this than directly interacting with the Store struct.
func (*ProductService) CreateProduct ¶
func (p *ProductService) CreateProduct(ctx context.Context, name string, price float64, stock int) (int, error)
CreateProduct stores a new product with the given name, price and stock.
func (*ProductService) GetProduct ¶
GetProduct returns the product associated with the given id if it exists.
func (*ProductService) GetProducts ¶
GetProducts returns a slice of products associated with the given name.
func (*ProductService) UpdateProduct ¶
func (p *ProductService) UpdateProduct(ctx context.Context, id int, name string, price float64, stock int) error
UpdateProduct updates a product with the given id.
func (*ProductService) UpdateProductStock ¶
UpdateProductStock updates the stock of the product associated with the specified id.