func (s *TaskDAOMongo) Delete(ID string) error {
	if _, err := uuid.FromString(ID); err != nil {
		return ErrInvalidUUID
	}
	session := s.session.Copy()
	defer session.Close()
	c := session.DB("").C(collection)
	err := c.Remove(bson.M{"id": ID})
	return err
}
Delete deletes a tasks by its ID
package dao
import (
	"github.com/Sfeir/golang-200/model"
	"github.com/satori/go.uuid"
	logger "github.com/sirupsen/logrus"
	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)
var _ TaskDAO = (*TaskDAOMongo)(nil)
const (
	collection = "tasks"
	index      = "id"
)
type TaskDAOMongo struct {
	session *mgo.Session
}
func NewTaskDAOMongo(session *mgo.Session) TaskDAO {
	err := session.DB("").C(collection).EnsureIndex(mgo.Index{
		Key:        []string{index},
		Unique:     true,
		DropDups:   true,
		Background: true,
		Sparse:     true,
	})
	if err != nil {
		logger.WithField("error", err).Warn("mongo db connection")
	}
	return &TaskDAOMongo{
		session: session,
	}
}
func (s *TaskDAOMongo) GetByID(ID string) (*model.Task, error) {
	if _, err := uuid.FromString(ID); err != nil {
		return nil, ErrInvalidUUID
	}
	session := s.session.Copy()
	defer session.Close()
	task := model.Task{}
	c := session.DB("").C(collection)
	err := c.Find(bson.M{"id": ID}).One(&task)
	if err != nil && err == mgo.ErrNotFound {
		return nil, ErrNotFound
	}
	return &task, err
}
func (s *TaskDAOMongo) getAllTasksByQuery(query interface{}, start, end int) ([]model.Task, error) {
	session := s.session.Copy()
	defer session.Close()
	c := session.DB("").C(collection)
	hasPaging := start > NoPaging && end > NoPaging && end >= start
	var err error
	var tasks []model.Task
	if hasPaging {
		err = c.Find(query).Skip(start).Limit(end - start + 1).All(&tasks)
	} else {
		err = c.Find(query).All(&tasks)
	}
	if err != nil && err == mgo.ErrNotFound {
		return nil, ErrNotFound
	}
	return tasks, err
}
func (s *TaskDAOMongo) GetAll(start, end int) ([]model.Task, error) {
	return s.getAllTasksByQuery(nil, start, end)
}
func (s *TaskDAOMongo) GetByTitle(title string) ([]model.Task, error) {
	return s.getAllTasksByQuery(bson.M{"title": title}, NoPaging, NoPaging)
}
func (s *TaskDAOMongo) GetByStatus(status model.TaskStatus) ([]model.Task, error) {
	return s.getAllTasksByQuery(bson.M{"status": status}, NoPaging, NoPaging)
}
func (s *TaskDAOMongo) GetByStatusAndPriority(status model.TaskStatus, priority model.TaskPriority) ([]model.Task, error) {
	return s.getAllTasksByQuery(bson.M{"status": status, "priority": priority}, NoPaging, NoPaging)
}
func (s *TaskDAOMongo) Save(task *model.Task) error {
	if len(task.ID) == 0 {
		task.ID = uuid.NewV4().String()
	}
	session := s.session.Copy()
	defer session.Close()
	c := session.DB("").C(collection)
	return c.Insert(task)
}
func (s *TaskDAOMongo) Upsert(task *model.Task) (bool, error) {
	if len(task.ID) == 0 {
		task.ID = uuid.NewV4().String()
	}
	session := s.session.Copy()
	defer session.Close()
	c := session.DB("").C(collection)
	chg, err := c.Upsert(bson.M{"id": task.ID}, task)
	if err != nil {
		return false, err
	}
	return chg.Updated > 0, err
}