Пример #1
0
func setup() {
	var t *testing.T
	available := db.AvailableTopic{
		Ident:    "high_prio_log_incoming",
		AppName:  validName,
		Channels: []string{"email", "web", "push"},
	}
	available.PrepareSave()
	err := db.Conn.Session.DB(dbName).C(db.AvailableTopicCollection).Insert(available)
	if err != nil {
		t.Error("Unable to setup db for testing")
	}
}
Пример #2
0
// 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")
}
Пример #3
0
func (self *Topics) Post(request *gottp.Request) {
	newTopic := new(db.AvailableTopic)
	newTopic.Channels = []string{"email", "web", "push"}

	request.ConvertArguments(newTopic)

	newTopic.PrepareSave()

	if !utils.ValidateAndRaiseError(request, newTopic) {
		log.Println("Validation Failed")
		return
	}

	if _, err := available_topics.Get(newTopic.Ident); err == nil {
		request.Raise(gottp.HttpError{
			http.StatusConflict,
			"Topic already exists"})
		return
	} else {
		if err != mgo.ErrNotFound {
			log.Println(err)
			request.Raise(gottp.HttpError{
				http.StatusInternalServerError,
				"Unable to fetch data, Please try again later.",
			})
			return
		}
	}

	available_topics.Insert(newTopic)

	request.Write(utils.R{
		StatusCode: http.StatusCreated,
		Data:       newTopic.Id,
		Message:    "Created",
	})
	return
}
Пример #4
0
// 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")
}