list

package
v0.0.0-...-e27359b Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package list provides functionality for managing lists.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteList

func DeleteList(w http.ResponseWriter, r *http.Request)

DeleteList deletes the list for the given tag. The currently logged in user must own the list. Otherwise, an unauthorized error is returned.

func GetAllLists

func GetAllLists(w http.ResponseWriter, r *http.Request)

GetAllLists fetches all of the lists.

func GetList

func GetList(w http.ResponseWriter, r *http.Request)

GetList fetches the list for the given tag.

func MakeMuxer

func MakeMuxer(prefix string) http.Handler

MakeMuxer creates a http.Handler to manage all list operations. If a prefix is given, that prefix will be the first part of the url. This muxer will provide the following handlers and return a RESTful 404 on all others.

GET     prefix + /        Get all lists.
POST    prefix + /        Create a new list.

GET     prefix + /{key}/  Get the list for the given key.
PUT     prefix + /{key}/  Update the list with the given key.
DELETE  prefix + /{key}/  Delete the list with the given key.

See the functions related to these urls for more details on what each one does and the requirements behind it.

func NewListHelper

func NewListHelper(c appengine.Context, w http.ResponseWriter,
	r *http.Request, l *List) bool

NewListHelper is a helper function that creates a new list in the datastore for the given list. The given list is updated with the keys. If a failure occured, false is returned and a response was returned to the request. This case should be terminal.

func PostList

func PostList(w http.ResponseWriter, r *http.Request)

PostList creates a new list from the POSTed data.

func PutList

func PutList(w http.ResponseWriter, r *http.Request)

PutList saves the list for the given tag.

func PutListHelper

func PutListHelper(c appengine.Context, w http.ResponseWriter,
	r *http.Request, l *List) bool

PutListHelepr saves the list and it's items to the datastore. If the list or any of it's items don't have a key, a key will be made for it.

Types

type Item

type Item struct {
	// A URL safe version of the datastores key for this list item.
	Key string `datastore:",noindex"`

	// The order of this item within the list. Lower numbers come before
	// higher numbers.
	Order int

	// The string representing the list item.
	Name string `datastore:",noindex"`

	// The state of completion of this list item..
	Completed bool `datastore:",noindex"`

	// If delete is true, when this item is merged with other items,
	// this item will be removed from the merged list. See
	// Merge for more information.
	Delete bool `datastore:"-"`
}

Item is a single item in a List.

type ItemsList

type ItemsList []*Item

ItemsList is a list of Items that has the ability reset the orders of it's itms based on the current position in the array.

func (ItemsList) SetOrders

func (li ItemsList) SetOrders()

SetOrders fixes the order of the items by setting each Items order to its current position in the array.

type List

type List struct {
	// The name of the list.
	Name string `datastore:",noindex"`

	// A URL safe version of the datastores key for this list. It
	// is not stored in the datastore.
	Key string `datastore:",noindex"`

	// This is the time the list was last modified.
	LastModified time.Time

	// The items in the list. This is used by the web
	// application. Within the datastore, these are children of the
	// list. The get, put, etc. functions will manage this automagically
	// if you use them.
	Items ItemsList `datastore:"-"`
}

List is the structure used to save, get, and delete lists from the datastore.

func GetListHelper

func GetListHelper(c appengine.Context, w http.ResponseWriter,
	r *http.Request, key string) (*List, bool)

GetListHelper is a helper function that retrieves a list and it's items from the datastore. If a failure occured, false is returned and a response was returned to the request. This case should be terminal.

func (*List) Merge

func (l *List) Merge(m *List) []string

Merge combines the Items in this List with the given List. The given list is considered the authority on the order of list items. The items are then given a new order based on their position in the array. A list of keys is returned of items that were removed.

func (*List) RemoveItem

func (l *List) RemoveItem(key string) *Item

RemoveItem looks through this List's Items and returns an Item matching the given key or nil if it was not found. If an item was found, it is removed from the list.

Jump to

Keyboard shortcuts

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