entity

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID int64

ID defines the type used to uniquely identify entities.

var InvalidID ID = -1

InvalidID corresponds to no entity.

type InventoryItem

type InventoryItem interface {
	ID() ID
	Name() string
	Location() string
	IsAvailable() bool
	Checkout() error
	CheckIn() error
	ChangeName(string) error
	ChangeLocation(string) error
}

InventoryItem defines a unique entity

type InventoryItemConstructor

type InventoryItemConstructor interface {
	Reincarnate(id ID, name string, location string, available bool) InventoryItem
	NewAvailable(name string, location string) (InventoryItem, error)
}

InventoryItemConstructor constructs InventoryItems

type InventoryItemConstructorImpl

type InventoryItemConstructorImpl struct{}

InventoryItemConstructorImpl implements InventoryItemConstructor

func NewInventoryItemConstructorImpl

func NewInventoryItemConstructorImpl() *InventoryItemConstructorImpl

NewInventoryItemConstructorImpl is a constructor

func (*InventoryItemConstructorImpl) NewAvailable

func (i *InventoryItemConstructorImpl) NewAvailable(name string, location string) (InventoryItem, error)

NewAvailable creates a brand new entity from the given parameters. The input is validated and will fail if appropriate. The resulting entity will not have a valid id (you will probably want to persist it to get one).

func (*InventoryItemConstructorImpl) Reincarnate

func (i *InventoryItemConstructorImpl) Reincarnate(id ID, name string, location string, available bool) InventoryItem

Reincarnate creates an entity which was already tested and accepted - but just needs to be restored. Thus, this method bypasses validation. It should be used from system-sources, e.g. a database, and not user sources, e.g. a request.

type InventoryItemImpl

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

InventoryItemImpl implements InventoryItem

func TestInventoryItemImplConstructor

func TestInventoryItemImplConstructor(
	id ID,
	name string,
	location string,
	available bool) *InventoryItemImpl

TestInventoryItemImplConstructor allows you to create an InventoryItemImpl, directly - bypassing the constructor service. It should ONLY be used in tests.

func (*InventoryItemImpl) ChangeLocation

func (i *InventoryItemImpl) ChangeLocation(location string) error

ChangeLocation will change the location of the inventory item, if it is valid. If it is not valid, it will return an error

func (*InventoryItemImpl) ChangeName

func (i *InventoryItemImpl) ChangeName(name string) error

ChangeName will change the name of the inventory item, if it is valid. If it is not valid, it will return an error

func (*InventoryItemImpl) CheckIn

func (i *InventoryItemImpl) CheckIn() error

CheckIn will mark the inventory item as available. If the inventory item is available, then an error is returned.

func (*InventoryItemImpl) Checkout

func (i *InventoryItemImpl) Checkout() error

Checkout will mark the inventory item as unavilable. If the inventory item is not available, then an error is returned.

func (*InventoryItemImpl) ID

func (i *InventoryItemImpl) ID() ID

ID returns the id.

func (*InventoryItemImpl) IsAvailable

func (i *InventoryItemImpl) IsAvailable() bool

IsAvailable will return true if the inventory item may be checked out - false otherwise.

func (*InventoryItemImpl) Location

func (i *InventoryItemImpl) Location() string

Location returns the name.

func (*InventoryItemImpl) Name

func (i *InventoryItemImpl) Name() string

Name returns the name.

type NotFoundError

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

NotFoundError is returned when an entity cannot be found for a given id and type.

func NewNotFoundError

func NewNotFoundError(_type string, id ID) *NotFoundError

NewNotFoundError is a constructor

func (*NotFoundError) Error

func (n *NotFoundError) Error() string

Jump to

Keyboard shortcuts

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