products

package
v0.0.0-...-bbf7e2a Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGrpcServer

func NewGrpcServer(port string, ps ProductsService) *grpc.Server

func NewSqlDb

func NewSqlDb(dburl string) (*sql.DB, error)

Types

type AddProductRequest

type AddProductRequest struct {
	Name  string
	Desc  string
	Price int64
	Stock int64
}

type ConsumerService

type ConsumerService interface {
	Consume(events []string) error
}

func NewEventConsumer

func NewEventConsumer(ch *amqp.Channel, exchangeName string, productsRepo ProductsRepository) ConsumerService

type DetailedProduct

type DetailedProduct struct {
	Id        uuid.UUID
	Name      string
	Desc      string
	Price     int64
	Stock     int64
	CreatedAt time.Time
}

type EventProducer

type EventProducer interface {
	Produce(key string, data []byte)
}

func NewEventProducer

func NewEventProducer(exchange string, ch *amqp.Channel) EventProducer

type ProductsRepository

type ProductsRepository interface {
	FetchProduct(id uuid.UUID) (*DetailedProduct, error)
	FetchAllProducts() ([]*DetailedProduct, error)
	AddProduct(id uuid.UUID, name string, desc string, price int64, stock int64) error

	UpdateInventoryAdd(id uuid.UUID, num int64) error
	UpdateInventorySubtract(id uuid.UUID, num int64) error
	UpdateInventoryDelete(id uuid.UUID) error
}

func NewProductsRepository

func NewProductsRepository(db *sql.DB) ProductsRepository

type ProductsService

type ProductsService interface {
	GetProduct(id uuid.UUID) (*DetailedProduct, error)
	GetProducts() ([]*DetailedProduct, error)
	AddProduct(req AddProductRequest) (*uuid.UUID, error)
	UpdateInventory(req UpdateInventoryRequest) error
}

func NewProductsService

func NewProductsService(repo ProductsRepository, p EventProducer) ProductsService

type UpdateInventoryRequest

type UpdateInventoryRequest struct {
	ProductId uuid.UUID
	Number    int64
	Type      int32
}

Jump to

Keyboard shortcuts

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