model

package
v0.0.0-...-86c91f4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stock

type Stock struct {
	ProductID int `json:"productId"`
	Units     int `json:"units"`
	TTL       int `json:"ttl"`
}

Stock represents the stock units of a product

func (*Stock) IsValid

func (s *Stock) IsValid() bool

IsValid determines if a Stock is valid

type StockData

type StockData struct {
	Units int `json:"units"`
	TTL   int `json:"ttl"`
}

StockData represents the data relative to stock

func (*StockData) IsValid

func (sd *StockData) IsValid() bool

IsValid validates a StockData

func (*StockData) ToStock

func (sd *StockData) ToStock(productID int) Stock

ToStock transforms a StockData into a Stock object

type StockError

type StockError struct {
	Code      int
	ProductID int
	Err       error
}

StockError model

func InternalError

func InternalError(productID int, err error) *StockError

InternalError returns an internal error object

func OutOfStockError

func OutOfStockError(productID int) *StockError

OutOfStockError is raised when a product has no stock

func (*StockError) Error

func (err *StockError) Error() string

func (*StockError) IsInternalError

func (err *StockError) IsInternalError() bool

IsInternalError checks if an error is an internal error

func (*StockError) IsOutOfStockError

func (err *StockError) IsOutOfStockError() bool

IsOutOfStockError checks if an error is an out of stock error

type StockList

type StockList struct {
	Stock      []Stock      `json:"stock"`
	OutOfStock []int        `json:"outOfStock"`
	Error      []StockError `json:"error"`
	// contains filtered or unexported fields
}

StockList represents the stock of a list of products

func (*StockList) AddStock

func (sl *StockList) AddStock(s *Stock)

AddStock adds a product with stock

func (*StockList) Get

func (sl *StockList) Get() StockList

Get returns a copy of the current instance

func (*StockList) HandleError

func (sl *StockList) HandleError(err *StockError)

HandleError handles the error my updating the corresponding field

func (*StockList) HasStock

func (sl *StockList) HasStock() bool

HasStock determines if there is stock available

func (*StockList) IsValid

func (sl *StockList) IsValid() bool

IsValid determines if a StockList is valid

Jump to

Keyboard shortcuts

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