Exemple #1
0
func Edit(w http.ResponseWriter, r *http.Request, dbConnection *bongo.Connection) {
	vars := mux.Vars(r)
	m, err := meeting.GetOne(vars["id"], dbConnection)
	if _, ok := err.(*bongo.DocumentNotFoundError); ok {
		http.NotFound(w, r)
	} else {
		data := struct {
			Meeting    *meeting.Meeting
			FormErrors map[string]string
		}{
			m,
			nil,
		}
		t := template.Must(template.ParseFiles("views/layouts/base.html", "views/meetings/edit.html"))
		t.Execute(w, data)
	}
}
Exemple #2
0
func Update(w http.ResponseWriter, r *http.Request, dbConnection *bongo.Connection) {
	m, err := meeting.GetOne(r.FormValue("id"), dbConnection)
	if _, ok := err.(*bongo.DocumentNotFoundError); ok {
		http.NotFound(w, r)
	}

	formErrors := m.Validate(r)
	if len(formErrors) > 0 {
		data := struct {
			Meeting    *meeting.Meeting
			FormErrors map[string]string
		}{
			m,
			formErrors,
		}
		t := template.Must(template.ParseFiles("views/layouts/base.html", "views/meetings/edit.html"))
		t.Execute(w, data)
	} else {
		err = dbConnection.Collection(meeting.CollectionName).Save(m)
		http.Redirect(w, r, "/meetings", 301)
	}
}