db

package
v0.0.0-...-a64decf Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InventoryService

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

InventoryService is our database type.

func NewInventoryService

func NewInventoryService(s map[string]MenuItem) *InventoryService

NewInventoryService creates a new service, given an map of items to initialise from.

func (*InventoryService) GetStock

func (s *InventoryService) GetStock() []MenuItem

GetStock returns the current stock available.

func (*InventoryService) PlaceOrder

func (s *InventoryService) PlaceOrder(items []LineItem) (float64, error)

PlaceOrder verifies quantities and place an order for the given slice of LineItem.

type LineItem

type LineItem struct {
	Name     string `json:"name"`
	Quantity int    `json:"quantity"`
}

LineItem contains all the different items of an Order.

type MenuItem struct {
	Name     string  `json:"name"`
	Quantity int     `json:"quantity"`
	Price    float64 `json:"price"`
}

MenuItem is the type of items available.

type Order

type Order struct {
	ID     string     `json:"id"`
	Items  []LineItem `json:"items"`
	Status string     `json:"status"`
	Total  string     `json:"total,omitempty"`
}

Order contains the fields of our orders.

type OrderService

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

OrderService is our database type.

func NewOrders

func NewOrders(inventory *InventoryService) *OrderService

NewOrders initialises the Orders service given an InventoryService.

func (*OrderService) Get

func (os *OrderService) Get(id string) (*Order, error)

Get returns a given order or error if none exists.

func (*OrderService) GetSales

func (os *OrderService) GetSales() *Sales

GetSales returns the sales stats of the order service This is a costly/long running operation.

func (*OrderService) Upsert

func (os *OrderService) Upsert(o Order) (Order, error)

Upsert creates or updates a new order.

type OrderStatus

type OrderStatus int

OrderStatus contains the different types of Order status.

const (
	New OrderStatus = iota
	InProgress
	Completed
	Rejected
)

func (OrderStatus) String

func (o OrderStatus) String() string

type Sales

type Sales struct {
	CompletedOrders int    `json:"completed_orders"`
	RejectedOrders  int    `json:"rejected_orders"`
	TotalRevenue    string `json:"total_revenue"`
}

Sales contains total sales and revenue of the ice cream van.

Jump to

Keyboard shortcuts

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