예제 #1
0
func CountFollowingBrandByUserId(userId bson.ObjectId) (num int, err error) {
	if !userId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountFollowBrand(bson.M{"userid": userId})
}
예제 #2
0
func CountReviewByBrandId(brandId bson.ObjectId) (num int, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountReview(bson.M{"brandid": brandId})
}
예제 #3
0
파일: blog.go 프로젝트: jango2015/bloggo
func (c Blog) GetRead(id bson.ObjectId) revel.Result {
	if id.Hex() != "" {
		article := models.GetArticleByObjectId(c.MongoSession, id)
		return c.Render(article)
	}
	return c.NotFound("Invalid article Id.")
}
예제 #4
0
func CountReviewByProductId(productId bson.ObjectId) (num int, err error) {
	if !productId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountReview(bson.M{"productid": productId})
}
예제 #5
0
파일: note_curd.go 프로젝트: kobeld/duoerl
func FindSomeByUserId(userId bson.ObjectId) (r []*Note, err error) {
	if !userId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"authorid": userId})
}
예제 #6
0
func FindById(id bson.ObjectId) (review *Review, err error) {
	if !id.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindOne(bson.M{"_id": id})
}
예제 #7
0
func FindByUserId(userId bson.ObjectId) (r []*FollowBrand, err error) {
	if !userId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"userid": userId})
}
예제 #8
0
func CountBrandFollowerByBrandId(brandId bson.ObjectId) (num int, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountFollowBrand(bson.M{"brandid": brandId})
}
예제 #9
0
func FindByBrandId(brandId bson.ObjectId) (r []*FollowBrand, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"brandid": brandId})
}
예제 #10
0
func FindByUserAndBrandId(userId, brandId bson.ObjectId) (followBrand *FollowBrand, err error) {
	if !userId.Valid() || !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindOne(bson.M{"userid": userId, "brandid": brandId})
}
예제 #11
0
파일: post_curd.go 프로젝트: kobeld/duoerl
func FindSomeByAuthorId(authorId bson.ObjectId) (r []*Post, err error) {
	if !authorId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"authorid": authorId})
}
예제 #12
0
func FindById(id bson.ObjectId) (product *Product, err error) {
	if !id.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindOne(bson.M{"_id": id})
}
예제 #13
0
파일: comments.go 프로젝트: Laller/hypecms
// Only called when doing update or delete.
// At inserting, user.OkayToDoAction is sufficient.
// This needs additional action: you can only update or delete a given comment only if it's yours (under a certain level).
func CanModifyComment(db *mgo.Database, inp map[string][]string, correction_level int, user_id bson.ObjectId, user_level int) error {
	rule := map[string]interface{}{
		"content_id": "must",
		"comment_id": "must",
		"type":       "must",
	}
	dat, err := extract.New(rule).Extract(inp)
	if err != nil {
		return err
	}
	// Even if he has the required level, and he is below correction_level, he can't modify other people's comment, only his owns.
	// So we query here the comment and check who is the owner of it.
	if user_level < correction_level {
		content_id_str := basic.StripId(dat["content_id"].(string))
		comment_id_str := basic.StripId(dat["comment_id"].(string))
		auth, err := findCommentAuthor(db, content_id_str, comment_id_str)
		if err != nil {
			return err
		}
		if auth.Hex() != user_id.Hex() {
			return fmt.Errorf("You are not the rightous owner of the comment.")
		}
	}
	return nil
}
예제 #14
0
func (a *AbstractModel) UpdateByPk(id bson.ObjectId, update interface{}) error {
	if !id.Valid() {
		return errors.New("20314")
	}

	return a.Update(M{"_id": id}, update, true)
}
예제 #15
0
func DeleteByUserAndBrandId(userId, brandId bson.ObjectId) (err error) {
	if !userId.Valid() || !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return DeleteFollowBrand(bson.M{"userid": userId, "brandid": brandId})
}
예제 #16
0
// 添加共享d笔记
func (this *NoteService) AddSharedNote(note info.Note, myUserId bson.ObjectId) info.Note {
	// 判断我是否有权限添加
	if shareService.HasUpdateNotebookPerm(note.UserId.Hex(), myUserId.Hex(), note.NotebookId.Hex()) {
		note.CreatedUserId = myUserId // 是我给共享我的人创建的
		return this.AddNote(note)
	}
	return info.Note{}
}
예제 #17
0
파일: utils.go 프로젝트: nangong92t/go_src
// 查找ObjectId数组中是否有指定值.
func ObjectIdInSlice(id bson.ObjectId, list []bson.ObjectId) bool {
	for _, b := range list {
		if b.Hex() == id.Hex() {
			return true
		}
	}
	return false
}
예제 #18
0
파일: mongo.go 프로젝트: raphael/gotcha
// Get document from id
func (s *session) GetId(col string, id bson.ObjectId, doc interface{}) error {
	c := s.db.C(col)
	err := c.FindId(id).One(doc)
	if err != nil {
		log.Printf("**ERROR: Could not lookup document with id %v from collection %v: %v", id.Hex(), col, err)
	}
	return err
}
예제 #19
0
func FindSomeByProductId(productId bson.ObjectId) (rs []*Review, err error) {
	if !productId.Valid() {
		err = global.InvalidIdError
		return
	}

	return FindAll(bson.M{"productid": productId})
}
예제 #20
0
func FindSomeByBrandId(brandId bson.ObjectId) (rs []*Review, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}

	return FindAll(bson.M{"brandid": brandId})
}
예제 #21
0
파일: main.go 프로젝트: minefold/pinky
func backupServer(serverId string, backupTime time.Time) (err error) {
	wip := <-wipGen.C
	defer close(wip)

	server := servers.Get(serverId)
	if server == nil {
		err = errors.New(fmt.Sprintf("no server for %s", serverId))
		return
	}

	var (
		url  string
		size int64
	)
	err = retry(1000, 5*time.Second, func(retries int) error {
		var err error
		url, size, err = server.BackupWorld(backupTime)
		if err != nil {
			plog.Error(err, map[string]interface{}{
				"event":    "world_backup",
				"serverId": serverId,
				"retries":  retries,
			})
		}
		return err
	})
	if err != nil {
		return
	}

	var snapshotId bson.ObjectId
	err = retry(1000, 5*time.Second, func(retries int) error {
		var err error
		snapshotId, err = StoreBackupInMongo(serverId, url, size, backupTime)
		if err != nil {
			plog.Error(err, map[string]interface{}{
				"event":    "world_db_store",
				"serverId": serverId,
				"retries":  retries,
			})

		}
		return err
	})

	pushPinkyEvent(map[string]interface{}{
		"ts":          time.Now(),
		"server_id":   serverId,
		"event":       "server_event",
		"type":        "backed_up",
		"snapshot_id": snapshotId.Hex(),
		"url":         url,
		"size":        size,
	})

	return
}
예제 #22
0
파일: dbctx.go 프로젝트: openvn/gocms
func (ctx *DBCtx) AllContact(offset bson.ObjectId, limit int) []Contact {
	conts := []Contact{}
	if offset.Valid() {
		ctx.contColl.Find(bson.M{"_id": bson.M{"$gt": offset}}).Limit(limit).All(&conts)
	} else {
		ctx.contColl.Find(nil).Limit(limit).All(&conts)
	}
	return conts
}
예제 #23
0
파일: api.go 프로젝트: jhyle/goevents
func (api *EventsApi) deleteImage(id bson.ObjectId) error {

	err := api.images.DeleteFile(api.images.GetBasePath() + string(os.PathSeparator) + id.Hex() + ".jpg")
	if err != nil {
		return err
	}

	api.imageCache.Remove(api.imageCache.FindKeys(id.Hex()))
	return nil
}
예제 #24
0
//-------------------------------------------------------
// methods
//-------------------------------------------------------
// obtain all the data and proceed to authorisation
func (d *Daemon) Authenticate(id bson.ObjectId) error {
	c := db.C("daemons")
	err := c.FindId(id).One(&d.Entry)
	if err == nil {
		d.Id = id.Hex()
		d.OrgId = d.Entry.OrgId.Hex()
		return d.Authorise()
	}
	return err
}
예제 #25
0
파일: user.go 프로젝트: GU-2013-TEAM-M/eos
//-------------------------------------------------------
// methods
//-------------------------------------------------------
// obtain all the data and proceed to authorisation
func (u *User) Authenticate(id bson.ObjectId) error {
	c := db.C("users")
	err := c.FindId(id).One(&u.Entry)
	if err == nil {
		u.Id = id.Hex()
		u.OrgId = u.Entry.OrgId.Hex()
		return u.Authorise()
	}
	return err
}
func mapFromFeed(feed *domain.Feed) feedDao {
	var id bson.ObjectId
	if len(feed.ID) > 0 {
		id = bson.ObjectIdHex(feed.ID)
	} else {
		id = bson.NewObjectId()
		feed.ID = id.Hex()
	}
	return feedDao{id, feed.Uri, feed.LastSync}
}
예제 #27
0
파일: utils.go 프로젝트: nangong92t/go_src
// 检测ObjectId数组中是否存在某一个id。
func ObjectIdIsIn(ids []bson.ObjectId, id bson.ObjectId) bool {
	result := false
	for i := 0; i < len(ids); i++ {
		if ids[i].Hex() == id.Hex() {
			result = true
			break
		}
	}

	return result
}
예제 #28
0
파일: user.go 프로젝트: jango2015/bloggo
func (c User) GetUpdate(id bson.ObjectId) revel.Result {
	if c.ActiveUser != nil {
		action := "/User/" + id.Hex()
		user := c.ActiveUser
		if user.CanBeUpdatedBy(c.MongoSession, c.ActiveUser) {
			return c.Render(action, user)
		}
		return c.Forbidden("You are not allowed to edit this resource.")
	}
	return c.Redirect(User.GetLogin)
}
예제 #29
0
파일: ref.go 프로젝트: mda747/go-start
// Implements bson.Setter for mongo.Ref compatibility.
// Yes this bson dependency is dirty, but necessary
// for transition form mongo.Ref to model.Ref.
func (self *Ref) SetBSON(raw bson.Raw) error {
	var objectId *bson.ObjectId
	if raw.Unmarshal(&objectId) == nil {
		if objectId != nil {
			*self = Ref(objectId.Hex())
		} else {
			*self = ""
		}
		return nil
	}
	return raw.Unmarshal(self)
}
예제 #30
0
func (table *mongoTable) CheckForId(id bson.ObjectId) error {

	count, err := table.CountById(id)
	if err != nil {
		return err
	}

	if count == 1 {
		return nil
	} else {
		return errors.New(table.collection.Name + " " + id.Hex() + " not found.")
	}
}