service

package
v0.0.0-...-4564669 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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

func (p *ProductService) GetProduct(ctx context.Context, id int) (*store.Product, error)

GetProduct returns the product associated with the given id if it exists.

func (*ProductService) GetProducts

func (p *ProductService) GetProducts(ctx context.Context, name string) ([]*store.Product, error)

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

func (p *ProductService) UpdateProductStock(ctx context.Context, id int, stock int) error

UpdateProductStock updates the stock of the product associated with the specified id.

Jump to

Keyboard shortcuts

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