Ejemplo n.º 1
0
/**
 * データストアから指定された単語を削除する
 * API
 */
func delete(w http.ResponseWriter, r *http.Request) {
	var c appengine.Context
	var u *user.User
	var query *datastore.Query
	var word string
	var iterator *datastore.Iterator
	var key *datastore.Key
	var err error
	var entity Entity

	word = r.FormValue("word")
	if word == "" {
		return
	}

	c = appengine.NewContext(r)
	u = user.Current(c)
	query = datastore.NewQuery("words").Filter("UserID =", u.ID).Filter("Word =", word)
	iterator = query.Run(c)

	for {
		key, err = iterator.Next(&entity)
		if err != nil {
			break
		}
		err = datastore.Delete(c, key)
		Check(c, err)
	}
}
Ejemplo n.º 2
0
// Finds the first matching hot bid in the list, and deletes it. Then, returns
// the corresponding "real" bid.
func findValidBid(c appengine.Context, iter *datastore.Iterator, now time.Time) (*datastore.Key, *Bid, error) {
	for {
		var hot hotBid
		key, e := iter.Next(hotBidCodec{&hot})
		if e == datastore.Done {
			break
		} else if e != nil {
			// Error case
			return nil, nil, e
		}

		if now.Before(hot.Expires) {
			if err := datastore.Delete(c, key); err != nil {
				return nil, nil, err
			}

			var bid Bid
			if err := datastore.Get(c, hot.BidKey, bidCodec{&bid}); err != nil {
				return nil, nil, err
			}
			return hot.BidKey, &bid, nil
		}
	}
	return nil, nil, nil
}
Ejemplo n.º 3
0
/**
 * すべての単語リストを取得する
 */
func get(c appengine.Context, u *user.User) []Entity {
	var result []Entity
	var query *datastore.Query
	var err error
	var iterator *datastore.Iterator
	var entity *Entity

	query = datastore.NewQuery("words").Filter("UserID =", u.ID)
	Check(c, err)

	err = nil
	result = make([]Entity, 0)
	entity = new(Entity)
	for iterator = query.Run(c); ; {
		_, err = iterator.Next(entity)
		if err != nil {
			break
		}
		result = append(result, *entity)
	}

	return result
}