Exemplo n.º 1
0
func SendNotification(pending_item *db.PendingItem) {
	userLocale, err := user_locale.Get(pending_item.User)
	if err != nil {
		log.Println("Unable to find locale for user", err.Error())
		userLocale = new(db.UserLocale)

		//FIXME:: Please do not hardcode this.
		userLocale.Locale = DEFAULT_LOCALE
		userLocale.TimeZone = DEFAULT_TIMEZONE
	}

	childwg := new(sync.WaitGroup)

	for channel, _ := range ChannelMap {
		childwg.Add(1)

		go func(
			locale, channelIdent string,
			pending_item *db.PendingItem,
		) {
			defer childwg.Done()
			send(locale, channelIdent, pending_item)
		}(userLocale.Locale, channel, pending_item)
	}

	childwg.Wait()
}
Exemplo n.º 2
0
func (self *UserLocale) Post(request *gottp.Request) {
	userLocale := new(db.UserLocale)
	request.ConvertArguments(userLocale)
	userLocale.PrepareSave()

	if !userLocale.IsValid() {
		request.Raise(gottp.HttpError{http.StatusBadRequest,
			"user, region_id and language_id must be present."})
		return
	}

	if !utils.ValidateAndRaiseError(request, userLocale) {
		return
	}

	dblocale, err := user_locale.Get(userLocale.User)

	if err != nil {
		if err != mgo.ErrNotFound {
			log.Println(err)
			request.Raise(gottp.HttpError{http.StatusInternalServerError,
				"Unable to fetch data, Please try again later."})
			return
		}
	}

	if dblocale != nil {
		request.Raise(gottp.HttpError{http.StatusConflict,
			"User locale information already exists"})
		return
	}

	user_locale.Insert(userLocale)

	request.Write(utils.R{Data: userLocale.Id, Message: "Created",
		StatusCode: http.StatusCreated})
	return
}