Esempio n. 1
0
func CountFollowingBrandByUserId(userId bson.ObjectId) (num int, err error) {
	if !userId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountFollowBrand(bson.M{"userid": userId})
}
Esempio n. 2
0
func FindById(id bson.ObjectId) (product *Product, err error) {
	if !id.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindOne(bson.M{"_id": id})
}
Esempio n. 3
0
func FindById(id bson.ObjectId) (review *Review, err error) {
	if !id.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindOne(bson.M{"_id": id})
}
Esempio n. 4
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)
}
Esempio n. 5
0
func FindSomeByUserId(userId bson.ObjectId) (r []*Note, err error) {
	if !userId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"authorid": userId})
}
Esempio n. 6
0
func CountBrandFollowerByBrandId(brandId bson.ObjectId) (num int, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountFollowBrand(bson.M{"brandid": brandId})
}
Esempio n. 7
0
func CountReviewByProductId(productId bson.ObjectId) (num int, err error) {
	if !productId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountReview(bson.M{"productid": productId})
}
Esempio n. 8
0
func CountReviewByBrandId(brandId bson.ObjectId) (num int, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return CountReview(bson.M{"brandid": brandId})
}
Esempio n. 9
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})
}
Esempio n. 10
0
func FindByUserId(userId bson.ObjectId) (r []*FollowBrand, err error) {
	if !userId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"userid": userId})
}
Esempio n. 11
0
func FindByBrandId(brandId bson.ObjectId) (r []*FollowBrand, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"brandid": brandId})
}
Esempio n. 12
0
func FindSomeByAuthorId(authorId bson.ObjectId) (r []*Post, err error) {
	if !authorId.Valid() {
		err = global.InvalidIdError
		return
	}
	return FindAll(bson.M{"authorid": authorId})
}
Esempio n. 13
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})
}
Esempio n. 14
0
func FindSomeByBrandId(brandId bson.ObjectId) (rs []*Review, err error) {
	if !brandId.Valid() {
		err = global.InvalidIdError
		return
	}

	return FindAll(bson.M{"brandid": brandId})
}
Esempio n. 15
0
func FindSomeByProductId(productId bson.ObjectId) (rs []*Review, err error) {
	if !productId.Valid() {
		err = global.InvalidIdError
		return
	}

	return FindAll(bson.M{"productid": productId})
}
Esempio n. 16
0
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
}
Esempio n. 17
0
func (ctx *DBCtx) EntryByTag(tag string, offset bson.ObjectId, limit int) []Entry {
	entrys := []Entry{}
	if offset.Valid() {
		ctx.entryColl.Find(bson.M{
			"_id":  bson.M{"$gt": offset},
			"tags": tag,
		}).Limit(limit).All(&entrys)
	} else {
		ctx.entryColl.Find(bson.M{"tags": tag}).Limit(limit).All(&entrys)
	}
	println(len(entrys))
	return entrys
}
Esempio n. 18
0
func (ctx *DBCtx) CatTree(root bson.ObjectId) []Catergory {
	all := []Catergory{}
	var query *mgo.Query

	if root.Valid() {
		query = ctx.catColl.Find(bson.M{"ancestors": root})
	} else {
		query = ctx.catColl.Find(bson.M{"parent": bson.M{"$exists": false}})
	}
	query.All(&all)

	return all
}
Esempio n. 19
0
func (self *Collection) DocumentLabel(docId bson.ObjectId, labelSelectors ...string) (string, error) {
	if !docId.Valid() {
		return "", fmt.Errorf("Invalid bson.ObjectId")
	}
	if len(labelSelectors) == 0 {
		labelSelectors = self.DocLabelSelectors
	}

	if len(labelSelectors) == 0 {
		// No label selectors, use hex ID as label
		count, err := self.collection.FindId(docId).Count()
		if err != nil {
			return "", err
		}
		if count == 0 {
			return "", fmt.Errorf("No document with ID '%s' in collection '%s'", docId.Hex(), self.Name)
		}
		return docId.Hex(), nil
	}

	labels := make([]string, len(labelSelectors))
	for i, selector := range labelSelectors {
		if len(selector) == 0 {
			return "", fmt.Errorf("Label selector must not be an empty string")
		}

		selector = strings.ToLower(selector)

		var doc bson.M
		err := self.collection.FindId(docId).Select(bson.M{selector: 1}).One(&doc)
		if err != nil {
			return "", err
		}

		var label interface{}
		if strings.IndexRune(selector, '.') != -1 {
			for _, subSel := range strings.Split(selector, ".") {
				label, _ = doc[subSel]
				if label == nil {
					break
				}
				doc, _ = label.(bson.M)
				if doc == nil {
					break
				}
			}
		} else {
			label, _ = doc[selector]
		}

		if label != nil {
			// Support the basic BSON types from unmarshalling
			switch s := label.(type) {
			case string:
				labels[i] = s

			case int:
				labels[i] = strconv.Itoa(s)

			case float64:
				labels[i] = strconv.FormatFloat(s, 'f', -1, 64)

			case bool:
				labels[i] = strconv.FormatBool(s)

			case bson.ObjectId:
				labels[i] = s.Hex()

			default:
				return "", fmt.Errorf("Can't get label of %s for '%s' because it is of type %T", docId.Hex(), selector, label)
			}
		}
	}

	label := strings.Join(labels, self.DocLabelSeparator)
	label = strings.TrimSpace(utils.RemoveMultipleWhiteSpace(label))

	return label, nil
}
Esempio n. 20
0
func FindById(id bson.ObjectId) (user *User, err error) {
	if !id.Valid() {
		return
	}
	return FindOne(bson.M{"_id": id})
}
Esempio n. 21
0
func FindById(id bson.ObjectId) (brand *Brand, err error) {
	if !id.Valid() {
		return
	}
	return FindOne(bson.M{"_id": id})
}