Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
DecreaseStock decreases the quantity of an item if sufficient
func (*Product) HasStock ¶
HasStock returns true is the stock is higher or equal to the requeted amount
func (*Product) IncreaseStock ¶
IncreaseStock adds the given quantity to the stock o
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 (*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