Exemple #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")
	}
}
Exemple #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")
}
Exemple #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
}