Esempio n. 1
0
func (ps BoltPostStore) Update(post *model.Post) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult
		postErr := post.IsValid()
		if postErr != nil {
			err := ps.postStore.Put([]byte(post.Id), []byte(post.ToJson()))

			if err != nil {
				result.Err = model.NewAppError("BoltPostStore.", "Post is not valid", "")
			} else {
				result.Data = post
			}
		} else {
			result.Err = postErr
		}

		storeChannel <- result
		close(storeChannel)
		return
	}()

	return storeChannel
}
Esempio n. 2
0
func (ps BoltPostStore) Save(post *model.Post) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult
		postErr := post.IsValid()
		if postErr != nil {
			post.PreSave()
			err := ps.postStore.Put([]byte(post.Id), []byte(post.ToJson()))

			postsByChannelsJson, err := ps.postsByChannel.Get([]byte(post.ChannelId))
			postsByChannelsString := string(postsByChannelsJson)
			postsByChannels := model.BoolMapFromJson(strings.NewReader(postsByChannelsString))
			postsByChannels[post.Id] = true

			postsByChannelsString = model.BoolMapToJson(postsByChannels)

			err = ps.postStore.Put([]byte(post.ChannelId), []byte(postsByChannelsString))

			if err != nil {
				result.Err = model.NewAppError("BoltPostStore.", "Post is valid", "")
			} else {
				result.Data = post
			}
		} else {
			result.Err = postErr
		}

		storeChannel <- result
		close(storeChannel)
		return
	}()

	return storeChannel
}