Documentation
¶
Overview ¶
Package app implements the back-end logic for the vet pharmacy administrating system. It implements a simple RESTful API that manages somehow the vet pharmacy warehouse.
Index ¶
Constants ¶
const ( MEDICINE stockType = iota FEED ACCESSORY )
MEDICINE, FEED and ACCESSORY are the default stock types in madmin
Variables ¶
This section is empty.
Functions ¶
func NewMAdminHandler ¶
func NewMAdminServer ¶
func NewMAdminServer(port, dbPath string) *madminServer
Types ¶
type CollectionResponseDTO ¶
CollectionResponseDTO is a data transfer object needed for the RESTful API implementation. It contains short information about the collection and the urls for each item in the collection.
type Distributor ¶
Distributor is a simple type interface for data about a stock distributor
func NewDistributor ¶
func NewDistributor(name string) (Distributor, error)
NewDistributor creates a new distributor with a UUID and a given name
type NewStockDTO ¶
type NewStockDTO struct {
Name string `json:"name"`
Type stockType `json:"type"`
Quantity string `json:"quantity"`
ExpirationDate string `json:"expirationDate"`
MinQuantity string `json:"minQuantity"`
DistributorID string `json:"distributorID"`
}
NewStockDTO is a data transfer object that can be used between reading a JSON with data for a new stock item and creating the new stock item with NewStock(*NewStockDTO) (Stock, error)
type Stock ¶
type Stock interface {
ID() string
Type() stockType
Name() string
SetName(string)
IsExpirable() bool
// IsExpirable() should always be chacked before trying to call ExpirationDate()
// or SetExpitrationDate(). Trying to get or set expiration date of an unexpirable
// stock causes panic.
ExpirationDate() time.Time
SetExpirationDate(time.Time)
MinQuantity() decimal.Decimal
SetMinQuantity(decimal.Decimal)
Quantity() decimal.Decimal
SetQuantity(decimal.Decimal)
DistributorID() string
SetDistributorID(string)
Update(StockDTO) error
}
Stock is a stock item interface
func NewAccessory ¶
func NewAccessory(dto *NewStockDTO) (Stock, error)
NewAccessory creates a new stock item of accessory type (unexpirable stock item). TODO: minimum quantity should be an integer, represented as decimal (should not have non-zero values after floating point)
func NewFeed ¶
func NewFeed(dto *NewStockDTO) (Stock, error)
NewFeed creates a new stock item of feed type (expirable stock item)
func NewMedicine ¶
func NewMedicine(dto *NewStockDTO) (Stock, error)
NewMedicine creates a new stock item of medicine type (expirable stock item)
func NewStock ¶
func NewStock(dto *NewStockDTO) (Stock, error)
NewStock creates a new valid Stock object. For now it only works for stock items of MEDICINE, FEED or ACCESSORY type.
type StockDTO ¶
type StockDTO struct {
ID string `json:"id"`
Name string `json:"name"`
Type stockType `json:"type"`
Quantity string `json:"quantity"`
ExpirationDate string `json:"expirationDate"`
MinQuantity string `json:"minQuantity"`
DistributorID string `json:"distributorID"`
}
StockDTO is a data transfer object that can be used for marshaling and unmarshaling an existing stock item
type StockTyper ¶
type StockTyper interface {
StockType() stockType
}
StockTyper is an interface that wraps the StockType method. StockType returns the type of a stock item
type User ¶
type User interface {
ID() string
Name() string
SetName(string)
Password() string
SetPassword(string) error
CheckPassword(string) bool
Salt() []byte
}
User is an application user's interface
type UserManager ¶
type UserManager interface {
CreateUser(User)
ReadUserById(string) (User, bool)
ReadUserByName(string) (User, bool)
UpdateUser(User)
RemoveUser(string)
ValidateUser(string, string) bool
}
func NewUserManager ¶
func NewUserManager(db *sql.DB) UserManager
type Warehouse ¶
type Warehouse interface {
CreateStock(Stock)
ReadStock(string) (Stock, bool)
UpdateStock(Stock)
DeleteStock(string)
CreateDistributor(Distributor)
ReadDistributor(string) (Distributor, bool)
UpdateDistributor(Distributor)
DeleteDistributor(string)
// Stock() returns a map with the ids of the current stock items in the DB,
// mapped to the corresponding stock items
Stock() map[string]Stock
// Size() returns number of unique stock items in DB
// TODO: should return number of all stock items in DB
Size() int
}
Warehouse is a warehouse interface. A warehouse must manage two datasets - one with the existing stock items and one with the stock items' distributors.
func NewWarehouse ¶
NewWarehouse creates a warehouse that holds the stock items' and distriubutors' data in two separate sqlite3 tables inside the db that is passed as an argument.