model

package
v0.0.0-...-bb5bdbf Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package model provides drink and inventory models for the backend of ABV.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date int64

Date is a representation of a Unix time stamp

type DateRange

type DateRange struct {
	Start Date
	End   Date
}

DateRange is an inclusive range of dates

type Drink

type Drink struct {
	Barcode   string
	Brand     string
	Name      string
	Abv       float64
	Ibu       int
	Type      string
	Shorttype string
	Date      Date
	Country   string
}

Drink stores information about an available beverage

type DrinkEntry

type DrinkEntry struct {
	Barcode  string
	Quantity int
	Date     Date
}

DrinkEntry defines quantities of drinks for transactions

type Model

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

Model controls all the data flow into and out of the db layer

func New

func New() (Model, error)

New creates a new fully initialized Model

func (*Model) BarcodeExists

func (m *Model) BarcodeExists(bc string) (bool, error)

BarcodeExists checks if a barcode is already in the database

func (*Model) ClearInputTable

func (m *Model) ClearInputTable() error

ClearInputTable deletes all stocking records

func (*Model) ClearOutputTable

func (m *Model) ClearOutputTable() error

ClearOutputTable deletes all serving records

func (*Model) CreateDrink

func (m *Model) CreateDrink(d Drink) (int, error)

CreateDrink adds an entry to the Drinks table, returning the id

func (*Model) CreateTablesIfNeeded

func (m *Model) CreateTablesIfNeeded()

CreateTablesIfNeeded ensures that the db has the necessary tables

func (*Model) DeleteDrink

func (m *Model) DeleteDrink(bc string) error

DeleteDrink removes an entry from the Drinks table using its barcode

func (*Model) GetAllStoredDrinks

func (m *Model) GetAllStoredDrinks() ([]Drink, error)

GetAllStoredDrinks returns every saved Drink row in the database

func (*Model) GetCountByBarcode

func (m *Model) GetCountByBarcode(bc string) (int, error)

GetCountByBarcode returns the total number of currently stocked beers with a specific barcode

func (*Model) GetDrinkByBarcode

func (m *Model) GetDrinkByBarcode(bc string) (Drink, error)

GetDrinkByBarcode returns all stored information about a drink based on its barcode

func (*Model) GetInputWithinDateRange

func (m *Model) GetInputWithinDateRange(dates DateRange) (result []StockedDrink, err error)

GetInputWithinDateRange returns every drink inputted within a date range, inclusive

func (*Model) GetInventory

func (m *Model) GetInventory() ([]StockedDrink, error)

GetInventory returns every drink with at least one quantity in stock, sorted by Type

func (*Model) GetInventorySorted

func (m *Model) GetInventorySorted(sortFields []string) ([]StockedDrink, error)

GetInventorySorted returns every drink with at least one quantity in stock, sorted by the provided Fields

func (*Model) GetInventoryTotalQuantity

func (m *Model) GetInventoryTotalQuantity() (int, error)

GetInventoryTotalQuantity returns the total number of beer bottles in stock

func (*Model) GetInventoryTotalVariety

func (m *Model) GetInventoryTotalVariety() (int, error)

GetInventoryTotalVariety returns the total number of beer varieties in stock

func (*Model) GetOutputWithinDateRange

func (m *Model) GetOutputWithinDateRange(dates DateRange) (result []StockedDrink, err error)

GetOutputWithinDateRange returns every drink served within a date range, inclusive

func (*Model) InputDrinks

func (m *Model) InputDrinks(d DrinkEntry) (int, error)

InputDrinks adds an entry to the Input table, returning the id

func (*Model) OutputDrinks

func (m *Model) OutputDrinks(d DrinkEntry) (int, error)

OutputDrinks adds an entry to the Output table, returning the id

func (*Model) UndoInputDrinks

func (m *Model) UndoInputDrinks(id int) error

UndoInputDrinks removes an entry from the Input table by id

func (*Model) UndoOutputDrinks

func (m *Model) UndoOutputDrinks(id int) error

UndoOutputDrinks removes an entry from the Output table by id

type StockedDrink

type StockedDrink struct {
	Drink
	Quantity int
}

StockedDrink is an extension of drink with an additional field for quantity

Jump to

Keyboard shortcuts

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