Esempio n. 1
0
func CreateFollowBrand(userId, brandId string) (err error) {

	userOId, err := utils.ToObjectId(userId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brandOId, err := utils.ToObjectId(brandId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	// Validation, check if the record has been created
	followBrand, err := followbrands.FindByUserAndBrandId(userOId, brandOId)
	if followBrand != nil {
		return
	}

	followBrand = &followbrands.FollowBrand{
		UserId:  userOId,
		BrandId: brandOId,
	}

	if err = followBrand.Save(); err != nil {
		utils.PrintStackAndError(err)
		return
	}

	return
}
Esempio n. 2
0
func GetFollowBrand(userId, brandId string) (followBrand *followbrands.FollowBrand) {
	userOId, err := utils.ToObjectId(userId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brandOId, err := utils.ToObjectId(brandId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	followBrand, _ = followbrands.FindByUserAndBrandId(userOId, brandOId)

	return
}