store

package
v0.0.0-...-6bf1803 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadSeeds

func LoadSeeds(seed io.Reader, db UnderlyingStore) error

LoadSeeds write the seed information to the DB.

Types

type Product

type Product struct {
	ID    uint   `json:"ID"`
	Name  string `json:"Name"`
	Price uint   `json:"Price"`
	Stock uint   `json:"Stock"`
}

Product models a shop product

func (*Product) DecreaseStock

func (p *Product) DecreaseStock(quantity uint) error

DecreaseStock decreases the quantity of an item if sufficient

func (*Product) GetPrice

func (p *Product) GetPrice() uint

GetPrice returns the amount of this product left in stock

func (*Product) GetStock

func (p *Product) GetStock() uint

GetStock returns the amount of this product left in stock

func (*Product) HasStock

func (p *Product) HasStock(quantity uint) bool

HasStock returns true is the stock is higher or equal to the requeted amount

func (*Product) IncreaseStock

func (p *Product) IncreaseStock(quantity uint)

IncreaseStock adds the given quantity to the stock o

func (*Product) Validate

func (p *Product) Validate() error

Validate checks that a user adheres to constraints

type ProductStore

type ProductStore interface {
	GetProductByID(ID uint) (*Product, error)
	SetProducts(products ...*Product) (*ProductTransaction, error)
}

ProductStore models the Product DB

func New

func New(log logger, db UnderlyingStore) ProductStore

New returns a new instance of ProductStore

type ProductTable

type ProductTable struct {
	// contains filtered or unexported fields
}

ProductTable represents the product table in the DB

func GetTable

func GetTable() *ProductTable

GetTable returns the product schema

func (*ProductTable) GetName

func (u *ProductTable) GetName() string

GetName return the name of the product table

func (*ProductTable) GetTableSchema

func (u *ProductTable) GetTableSchema() *memdb.TableSchema

GetTableSchema returns the schema for the products table

type ProductTransaction

type ProductTransaction struct {
	// contains filtered or unexported fields
}

ProductTransaction is used to externalize transactions

func (*ProductTransaction) Abort

func (r *ProductTransaction) Abort()

Abort is used to cancel this transaction

func (*ProductTransaction) Commit

func (r *ProductTransaction) Commit()

Commit is used to finalyze this transaction

func (*ProductTransaction) Write

func (r *ProductTransaction) Write(product *Product) error

Write inserts intp storace

type UnderlyingStore

type UnderlyingStore interface {
	Read(table string, key string, value interface{}) (interface{}, error)
	Write(table string, value ...interface{}) error
	WriteAndBlock(table string, value ...interface{}) (store.Transaction, error)
}

UnderlyingStore represents the interface that the DB should implement to be usable

type Validatable

type Validatable interface {
	Validate() error
}

Validatable is an item which has to adhere to certain convetions and knows how to check that it is correct

Directories

Path Synopsis
Package mock_store is a generated GoMock package.
Package mock_store is a generated GoMock package.

Jump to

Keyboard shortcuts

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