// Create an event func Create(c *gin.Context) { db := c.MustGet("db").(*mgo.Database) event := kdb.AvailableTopic{} err := c.Bind(&event) if err != nil { c.Error(err) return } event.PrepareSave() event.Ident = sanitize(event.Ident) err = db.C(kdb.AvailableTopicCollection).Insert(event) if err != nil { c.Error(err) } c.Redirect(http.StatusMovedPermanently, "/events") }
// Update an event func Update(c *gin.Context) { db := c.MustGet("db").(*mgo.Database) event := kdb.AvailableTopic{} err := c.Bind(&event) if err != nil { c.Error(err) return } query := bson.M{"_id": bson.ObjectIdHex(c.Param("_id"))} event.Ident = sanitize(event.Ident) doc := bson.M{ "ident": event.Ident, "app_name": event.AppName, "channels": event.Channels, "updated_on": time.Now().UnixNano() / int64(time.Millisecond), } err = db.C(kdb.AvailableTopicCollection).Update(query, doc) if err != nil { c.Error(err) } c.Redirect(http.StatusMovedPermanently, "/events") }