// 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) } } }
// Add Event from Website (incomplete) func EventAddHandler(w http.ResponseWriter, req *http.Request) { // Public facing page that allows users (required field email and event title) to submit a topic // TODO: implement check to ensure user submitted event provides an email var eventadd = template.Must(template.ParseFiles( path.Join(conf.Config.ProjectRoot, "templates/_base.html"), path.Join(conf.Config.ProjectRoot, "templates/event_add.html"), )) type templateData struct { Context *conf.Context } data := templateData{conf.DefaultContext(conf.Config)} // if request method is a GET, we will simply render the page if req.Method != "POST" { eventadd.Execute(w, data) return } // else if it is a POST, let's add our event event := NewEvent() event.Name = req.FormValue("name") event.Description = req.FormValue("description") // TODO: validation //if event.Name == "" { //fmt.Println("No event name submitted") //} //if event.Description == "" { //fmt.Println("No event description submitted") //} db.Upsert(event) http.Redirect(w, req, "/", http.StatusTemporaryRedirect) }