예제 #1
0
파일: datastore.go 프로젝트: liyu4/home
// 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 GetListHelper(c appengine.Context, w http.ResponseWriter,
	r *http.Request, key string) (*List, bool) {

	// Decode the string version of the key.
	k, err := datastore.DecodeKey(key)
	if err != nil {
		gorca.LogAndUnexpected(c, w, r, err)
		return nil, false
	}

	// Get the list by key.
	var l List
	if err := datastore.Get(c, k, &l); err != nil {
		gorca.LogAndNotFound(c, w, r, err)
		return nil, false
	}

	// Get all of the items for the list.
	var li ItemsList
	q := datastore.NewQuery("Item").Ancestor(k).Order("Order")
	if _, err := q.GetAll(c, &li); err != nil {
		gorca.LogAndUnexpected(c, w, r, err)
		return nil, false
	}

	l.Items = li

	return &l, true
}
예제 #2
0
파일: datastore.go 프로젝트: liyu4/home
// GetRecipeHelper is a helper function that retrieves a recipe 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 GetRecipeHelper(c appengine.Context, w http.ResponseWriter,
	r *http.Request, key string) (*Recipe, bool) {

	// Decode the string version of the key.
	k, err := datastore.DecodeKey(key)
	if err != nil {
		gorca.LogAndUnexpected(c, w, r, err)
		return nil, false
	}

	// Get the recipe by key.
	var recipe Recipe
	if err := datastore.Get(c, k, &recipe); err != nil {
		gorca.LogAndNotFound(c, w, r, err)
		return nil, false
	}

	return &recipe, true
}