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) }
func NotFoundHandler(r render.Render) { type templateData struct { Context *conf.Context } data := templateData{conf.DefaultContext(conf.Config)} r.HTML(200, "404", data) }
func HomeHandler(r render.Render) { type templateData struct { Context *conf.Context } data := templateData{conf.DefaultContext(conf.Config)} r.HTML(200, "home", data) }
func EventGrabHandler(r render.Render) { type templateData struct { Context *conf.Context } data := templateData{conf.DefaultContext(conf.Config)} r.HTML(200, "event_grab", data) }
func FacebookLoginHandler(r render.Render) { // simple static page for user to click on fb connect button type templateData struct { Context *conf.Context } data := templateData{conf.DefaultContext(conf.Config)} r.HTML(200, "facebook_login", data) }
func FacebookChannelHandler(w http.ResponseWriter, req *http.Request) { var fbchannel = template.Must(template.ParseFiles( path.Join(conf.Config.ProjectRoot, "templates/channel.html"), )) type templateData struct { Context *conf.Context } data := templateData{conf.DefaultContext(conf.Config)} fbchannel.Execute(w, data) }
func ShowEventAttendees(params martini.Params, mdb *mgo.Database, r render.Render) { fmt.Println("Show event attendees") var attendees []Attendee fmt.Println(params["eid"]) mdb.C("attendees").Find(bson.M{"eid": params["eid"]}).All(&attendees) type templateData struct { Context *conf.Context Attendees []Attendee } data := templateData{conf.DefaultContext(conf.Config), attendees} r.HTML(200, "event_attendees", data) }
// 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) }
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) }