Example #1
0
File: site.go Project: wuxu92/snp
func GetSiteById(id bson.ObjectId) Site {
	c := utils.GetMgc().GetDB().C("site")
	site := Site{}
	err := c.FindId(id).One(&site)
	utils.ErrChk(err)
	return site
}
Example #2
0
File: grp.go Project: wuxu92/snp
func (this *Group) Copy() Group {
	grp := Group{
		bson.NewObjectId(),
		time.Now().Format(time.RFC3339),
		this.Title,
		this.Owner,
		this.GroupLink,
		true,
		true,
		this.Id.Hex(),
		this.AdditionalStyle,
		nil,
		1,
	}
	sites := make([]bson.ObjectId, len(this.Sites))
	for idx, siteId := range this.Sites {
		old := GetSiteById(siteId)
		tmpSite := old.Copy()
		sites[idx] = tmpSite.Id
	}
	grp.Sites = sites
	// save group to mongo
	c := utils.GetMgc().GetDB().C("grp")
	err := c.Insert(&grp)
	utils.ErrChk(err)
	return grp
}
Example #3
0
File: grp.go Project: wuxu92/snp
func GetGroupById(id bson.ObjectId) Group {
	// db := utils.GetMgc().GetDB()
	c := utils.GetMgc().GetDB().C("grp")
	grp := Group{}
	err := c.FindId(id).One(&grp)
	utils.ErrChk(err)
	return grp
}
Example #4
0
File: pkg.go Project: wuxu92/snp
/**
 * check if a name already exist
 */
func CheckPkgName(name string) bool {
	mgc := utils.GetMgc()
	c := mgc.GetDB().C("pkg")

	n, err := c.Find(bson.M{"name": name}).Count()
	utils.ErrChk(err)
	if n > 0 {
		return true
	} else {
		return false
	}
}
Example #5
0
File: site.go Project: wuxu92/snp
func (this *Site) Copy() Site {
	site := Site{
		bson.NewObjectId(),
		this.Title,
		this.Url,
		time.Now().Format(time.RFC3339),
		true,
	}
	c := utils.GetMgc().GetDB().C("site")
	err := c.Insert(&site)
	utils.ErrChk(err)
	return site
}