Beispiel #1
0
func handleCreateIncident(w http.ResponseWriter, r *http.Request) {
	err := r.ParseForm()
	if err != nil {
		http.Error(w, http.StatusText(500), 500)
	}
	incident := domain.Incident{Values: make(map[string]interface{})}
	for k, v := range r.Form {
		incident.Values[k] = v[0]
	}
	incident.Status = domain.Draft
	db.SaveIncident(incident)
	http.Redirect(w, r, "/", 301)
}
Beispiel #2
0
// SaveIncident - Saves or Updates the passed in incident to the database
func SaveIncident(incident domain.Incident) {
	doneInsert := make(chan bool)
	go func() {
		if incident.ID == 0 {
			incident.ID = GetNextSequence("increp", "incidents") + 1
			Save(incident, "increp", "incidents")
			CreateIncidentIndex(incident)
			doneInsert <- true
		} else {
			Update(incident, bson.M{"ID": incident.ID}, "increp", "incidents")
			CreateIncidentIndex(incident)
			doneInsert <- true
		}
	}()
	<-doneInsert
}