Пример #1
0
func (d *DatastoreStorage) GetArchivedPosts(req *http.Request, datespec string) []blogplus.Activity {
	c := appengine.NewContext(req)
	datespecKey := datastore.NewKey(c, datespecKind, datespec, 0, nil)
	q := datastore.NewQuery(activityRef).Ancestor(datespecKey)
	t := q.Run(c)
	var keys []*datastore.Key
	for {
		var de DatespecEntity
		_, err := t.Next(&de)
		if err == datastore.Done {
			break
		}
		if err != nil {
			c.Errorf("query error:%#v", err)
			break
		}
		keys = append(keys, de.Id)
	}
	aelist := make([]ActivityEntity, len(keys))
	err := datastore.GetMulti(c, keys, aelist)
	if err != nil {
		c.Errorf("get multi error:%#v", err)
		return nil
	}
	var posts []blogplus.Activity
	for _, ae := range aelist {
		post, err := blogplus.DecodeActivity(ae.Post)
		if err != nil {
			c.Errorf("decode error:%#v", err)
			continue
		}
		posts = append(posts, post)
	}
	return posts
}
Пример #2
0
func (d *DatastoreStorage) GetPost(req *http.Request, activityId string) (post blogplus.Activity, ok bool) {
	c := appengine.NewContext(req)
	k := datastore.NewKey(c, activityKind, activityId, 0, nil)
	var ae ActivityEntity
	if err := datastore.Get(c, k, &ae); err != nil {
		c.Errorf("get error:%#v", err)
		return post, false
	}
	post, err := blogplus.DecodeActivity(ae.Post)
	if err != nil {
		c.Errorf("decode error:%#v", err)
		return post, false
	}
	return post, true
}
Пример #3
0
func (d *DatastoreStorage) GetLatestPosts(req *http.Request) []blogplus.Activity {
	c := appengine.NewContext(req)
	q := datastore.NewQuery(activityKind).Order("-Published").Limit(10)
	t := q.Run(c)
	var posts []blogplus.Activity
	for {
		var ae ActivityEntity
		_, err := t.Next(&ae)
		if err == datastore.Done {
			break
		}
		if err != nil {
			c.Errorf("query error:%#v", err)
			break
		}
		post, err := blogplus.DecodeActivity(ae.Post)
		if err != nil {
			c.Errorf("decode error:%#v", err)
			continue
		}
		posts = append(posts, post)
	}
	return posts
}