func VoteOnItem(dir models.VoteDirection, itemID string, user *models.User) error {
	vote := models.Vote{
		User:   user,
		Action: dir,
		Item:   itemID,
	}
	if err := vote.InsertOrUpdate(); err != nil {
		beego.Error(err)
		return errors.New("cannot vote on item")
	}
	return nil
}
VoteOnItem adds a vote to the database.
Item can be a comment or post.
The vote direction is saved as action.
package lib
import (
	"errors"
	"net/http"
	"net/url"
	"strconv"
	"strings"
	"github.com/astaxie/beego"
	"github.com/KeKsBoTer/socialloot/models"
)
func Submit(title, content string, postType models.PostType, topic *models.Topic, user *models.User) (*models.Post, error) {
	post := models.Post{
		Title: title,
		Topic: topic,
		Type:  postType,
		User:  user,
	}
	switch postType {
	case models.PostTypeText:
		post.Content = content
	case models.PostTypeLink:
		parsed, err := url.ParseRequestURI(content)
		if err != nil || !parsed.IsAbs() {
			return nil, errors.New("Invalid url format for link")
		}
		post.Content = parsed.String()
	case models.PostTypeImage:
		fileType := http.DetectContentType([]byte(content))
		mediaImage, err := parseImage(&content, fileType)
		if err != nil {
			beego.Error(err)
			return nil, errors.New("Cannot decode/encode image")
		}
		if err := mediaImage.Insert(); err != nil {
			beego.Error(err)
			return nil, errors.New("Cannot save image")
		}
		if mediaImage.Id == 0 {
			return nil, errors.New("Image Id not available")
		}
		post.Content = strconv.Itoa(mediaImage.Id)
	default:
		return nil, errors.New("Invalid post type")
	}
	post.Id = GenerateItemID()
	if err := post.Insert(); err != nil {
		beego.Error(err)
		return nil, errors.New("Cannot submit post")
	}
	return &post, nil
}
func CreateTopic(name, title, description string) (*models.Topic, error) {
	topic := models.Topic{
		Name:        strings.ToLower(name),
		Title:       title,
		Description: description,
	}
	if err := topic.Insert(); err != nil {
		beego.Error(err)
		return nil, errors.New("Cannot create topic")
	}
	if err := topic.Read("name"); err != nil {
		beego.Error(err)
		return nil, errors.New("An unexpected error occured")
	}
	return &topic, nil
}