list

package
v0.0.0-...-905f740 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: Unlicense Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalList

func MarshalList(l *List) ([]byte, error)

MarshalList marshals a list to json

Types

type Category

type Category struct {
	DateCreated  time.Time   `json:"created" html:"created"`
	DateModified time.Time   `json:"modified" html:"modified"`
	Items        []*ListItem `json:"items" html:"items"`
	CategoryName string      `json:"name" html:"name"`
	Value        float64     `json:"value" html:"value"`
	Length       int         `json:"length" html:"length"`
	NilItem      *ListItem   `json:"nil" html:"nil"`
}

Category is a subsection of a list. They are optional

func (*Category) DeleteItem

func (c *Category) DeleteItem(li *ListItem) error

DeleteItem removes an item from a category

func (*Category) Index

func (c *Category) Index(li *ListItem) (int, error)

This is super convoluted. We'll clean it up in the refactor

func (*Category) Search

func (c *Category) Search(s string, ch chan *ListItem, wg *sync.WaitGroup)

Search looks for an item within a category

func (*Category) SortItemsByChecked

func (c *Category) SortItemsByChecked()

SortItemsByChecked sorts items in a category by whether or not they have been marked as bought, then subsorts those sets alphabetically. At some point this hopefully will be able to work in conjunction with any of the other ones. And honestly this should probably just be handled in JS

func (*Category) SortItemsByCost

func (c *Category) SortItemsByCost()

SortItemsByCost sorts items in a category by cost, from least to most expensive

func (*Category) SortItemsByDate

func (c *Category) SortItemsByDate()

SortItemsByDate sorts items in a category by when they were added

func (*Category) SortItemsByName

func (c *Category) SortItemsByName()

SortItemsByName sorts items in a category alphabetically by name

type List

type List struct {
	DateCreated     time.Time   `json:"created" html:"created"` //I'll eventually convert these to uint64 for unix time
	DateModified    time.Time   `json:"modified" html:"modified"`
	ListID          string      `json:"id" html:"id"`
	Family          string      `json:"family" html:"family"`
	NilCategory     *Category   `json:"nil_category" html:"nil_category"`
	NilItem         *ListItem   `json:"nil" html:"nil"`
	ListOwner       string      `json:"owner" html:"owner"`           //I'm thinking this can be a group
	ListOwnerName   string      `json:"owner_name" html:"owner_name"` //For a group, this will be something like "Bill and Ted's list" if they have a joined list
	Categories      []*Category `json:"categories" html:"categories"`
	Value           float64     `json:"value" html:"value"`
	Length          int         `json:"length" html:"length"`
	NumOfCategories int         `json:"number_of_categories" html:"number_of_categories"`
	// contains filtered or unexported fields
}

List holds information about a Christmas list

func NewList

func NewList(family, id, owner, ownername string) *List

NewList returns a new list

func UnmarshalList

func UnmarshalList(b []byte) (*List, error)

UnmarshalList takes a slice of bytes and marshals it to a list struct

func (*List) DeleteCategory

func (l *List) DeleteCategory(s string) error

DeleteCategory removes a category and all its items from a list The remaining categories retain their sorted order. The function returns a non-nil error if deletion is unsuccessful

func (*List) DeleteItem

func (l *List) DeleteItem(c *Category, li *ListItem) error

DeleteItem wraps the Category "delete" method for Lists

func (*List) FindCategory

func (l *List) FindCategory(s string) (*Category, error)

FindCategory takes a string input and finds the category of that name

func (*List) NewCategory

func (l *List) NewCategory(s string) (*Category, error)

func (*List) NewItem

func (l *List) NewItem(category, name, url, description string, cost float64) error

newItem wraps the same method from the Category type, so that the List type can benefit from the length and cost portions

func (*List) Purchase

func (l *List) Purchase(it, m string, price float64) error

Purchase updates an item in a list so that its "checked" bool is true. It takes an string argument for the item name, a string argument for the name of the purchaser, and a price float64 value, and returns a non-nil error if the item was not found or if it was already purchased and is not a multi-purchase item

func (*List) RenameCategory

func (l *List) RenameCategory(c *Category, s string)

RenameCategory takes a category argument and a string argument and changes the name of the given category to the given string

func (*List) Search

func (l *List) Search(s string) (*ListItem, error)

Search looks for an item by name

func (*List) SortByDateAdded

func (l *List) SortByDateAdded()

SortByDateAdded sorts categories by date added

func (*List) SortByName

func (l *List) SortByName()

SortByName sorts categories alphabetically by name

type ListItem

type ListItem struct {
	DateCreated   time.Time   `json:"created" html:"created"`
	DateModified  time.Time   `json:"modified" html:"modified"`
	ItemName      string      `json:"name" html:"name"`
	Cost          float64     `json:"cost" html:"cost"`
	URL           string      `json:"url" html:"url"`
	Description   []byte      `json:"description" html:"description"`
	Checked       bool        `json:"checked" html:"checked"`               //true if someone has bought the item
	MultiPurchase bool        `json:"multi_purchase" html:"multi_purchase"` //this should be true if more than one person may purchase the item, e.g. socks or coffee
	Purchases     []*Purchase `json:"purchases" html:"purchases"`
}

ListItem holds information about a list item

type Purchase

type Purchase struct {
	PurchaseDate time.Time `json:"purchase_date" html:"purchase_date"`
	Purchaser    string    `json:"purchaser" html:"purchaser"`
	PricePaid    float64   `json:"price_paid" html:"price_paid"` //make sure this isn't seen by other members
}

Purchase holds name of purchaser, date of purchase, and price paid

Jump to

Keyboard shortcuts

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