func EventListHandler(r render.Render) { search := bson.M{"data.start_time": bson.M{"$gte": time.Now()}} sort := "data.start_time" var results []Event err := db.Find(&Event{}, search).Sort(sort).All(&results) if err != nil && err != mgo.ErrNotFound { panic(err) } if err == mgo.ErrNotFound { fmt.Println("No such object in db. Redirect") //http.Redirect(w, r, "/404/", http.StatusFound) return } type templateData struct { Context *conf.Context Events []Event } data := templateData{conf.DefaultContext(conf.Config), results} r.HTML(200, "event_list", data) }
// helper function which updates the events given a slice of event ids (string) and the token func updateEventDetails(event_ids []string, token *facebook.AccessToken) { for i := 0; i < len(event_ids); i++ { e := facebook.GetEvent(token, event_ids[i]) var result *Event err := db.Find(&Event{}, bson.M{"eid": e.Id}).One(&result) if err != nil { // Not found, so insert our event object event := wrangleData(e) db.Upsert(event) } else { // Already exists, so simply update as the retrieved result object result := wrangleData(e) db.Upsert(result) } } }
func EventNextHandler(r render.Render) { search := bson.M{"data.start_time": bson.M{"$gte": time.Now()}} sort := "data.start_time" var results []Event err := db.Find(&Event{}, search).Sort(sort).Limit(2).All(&results) fmt.Println(results) if err != nil && err != mgo.ErrNotFound { panic(err) } type templateData struct { Context *conf.Context Events []Event } data := templateData{conf.DefaultContext(conf.Config), results} r.HTML(200, "event_next", data) }