当前位置: 首页>>代码示例>>Golang>>正文


Golang utils.ToObjectId函数代码示例

本文整理汇总了Golang中github.com/kobeld/duoerl/utils.ToObjectId函数的典型用法代码示例。如果您正苦于以下问题:Golang ToObjectId函数的具体用法?Golang ToObjectId怎么用?Golang ToObjectId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ToObjectId函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CreateFollowBrand

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
}
开发者ID:kobeld,项目名称:duoerl,代码行数:32,代码来源:followbrand_services.go

示例2: CreatePost

func CreatePost(input *duoerlapi.PostInput) (originInput *duoerlapi.PostInput, err error) {
	originInput = input

	// simple validation
	if input.Content == "" {
		err = global.CanNotBeBlankError
		return
	}

	postId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	authorId, err := utils.ToObjectId(input.AuthorId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	post := &posts.Post{
		Id:       postId,
		Content:  input.Content,
		AuthorId: authorId,
	}

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

	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:34,代码来源:post_services.go

示例3: AddWishItem

func AddWishItem(userId, productId string) (err error) {

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

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

	// Validation, check if the record has been created
	wishItem, err := wishitems.FindByUserAndProductId(userOId, productOId)
	if wishItem != nil {
		return
	}

	wishItem = &wishitems.WishItem{
		UserId:    userOId,
		ProductId: productOId,
	}

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

	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:32,代码来源:wish_item_services.go

示例4: CreateNote

func CreateNote(input *duoerlapi.NoteInput) (originInput *duoerlapi.NoteInput, err error) {
	originInput = input

	noteId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	authorId, err := utils.ToObjectId(input.AuthorId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	note := &notes.Note{
		Id:      noteId,
		Article: *articles.NewArticle(input.Title, input.Content, authorId),
	}

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

	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:27,代码来源:note_services.go

示例5: AddOwnItem

func AddOwnItem(ownItemInput *duoerlapi.OwnItemInput) (err error) {

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

	productOId, err := utils.ToObjectId(ownItemInput.ProductId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	// Validation, check if the record has been created
	ownItem, err := ownitems.FindByUserAndProductId(userOId, productOId)
	if ownItem != nil {
		return
	}

	ownItem = &ownitems.OwnItem{
		UserId:    userOId,
		ProductId: productOId,
		GotFrom:   ownItemInput.GotFrom,
	}

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

	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:33,代码来源:own_item_services.go

示例6: CreateProduct

// Todo: validation needed. Idea: validate the input object
func CreateProduct(input *duoerlapi.ProductInput) (originInput *duoerlapi.ProductInput, err error) {
	originInput = input

	oId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brandObjectId, err := utils.ToObjectId(input.BrandId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	categoryOId, err := utils.ToObjectId(input.CategoryId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	subCategoryOId, err := utils.ToObjectId(input.SubCategoryId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	authorOId, err := utils.ToObjectId(input.AuthorId)
	if err != nil {
		// Don't return
		utils.PrintStackAndError(err)
	}

	product := &products.Product{
		Id:            oId,
		BrandId:       brandObjectId,
		Name:          input.Name,
		Alias:         input.Alias,
		Intro:         input.Intro,
		Image:         input.Image,
		AuthorId:      authorOId,
		CategoryId:    categoryOId,
		SubCategoryId: subCategoryOId,
		EfficacyIds:   utils.TurnPlainIdsToObjectIds(input.EfficacyIds),
	}

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

	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:54,代码来源:product_services.go

示例7: UpdateProduct

// Todo: validation needed. Idea: validate the input object
func UpdateProduct(input *duoerlapi.ProductInput) (originInput *duoerlapi.ProductInput, err error) {
	// When the validation fails, should giving back the originInput for front-end renderring
	originInput = input

	oId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brandObjectId, err := utils.ToObjectId(input.BrandId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	categoryOId, err := utils.ToObjectId(input.CategoryId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	subCategoryOId, err := utils.ToObjectId(input.SubCategoryId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	product, err := products.FindById(oId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	product.BrandId = brandObjectId
	product.Name = input.Name
	product.Alias = input.Alias
	product.Image = input.Image
	product.Intro = input.Intro
	product.CategoryId = categoryOId
	product.SubCategoryId = subCategoryOId
	product.EfficacyIds = utils.TurnPlainIdsToObjectIds(input.EfficacyIds)

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

	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:51,代码来源:product_services.go

示例8: ShowBrand

func ShowBrand(brandId, userId string) (apiBrand *duoerlapi.Brand, err error) {
	brandOId, err := utils.ToObjectId(brandId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brand, err := brands.FindById(brandOId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	apiBrand = toApiBrand(brand)
	apiBrand.BrandStats = getBrandStats(brandOId)

	// Not login user
	if userId == "" {
		return
	}

	if followBrand := GetFollowBrand(userId, brandId); followBrand != nil {
		apiBrand.HasFollowed = true
	}

	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:27,代码来源:brand_services.go

示例9: UpdateBrand

func UpdateBrand(input *duoerlapi.BrandInput) (originInput *duoerlapi.BrandInput, err error) {
	originInput = input

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

	brand, err := brands.FindById(brandOId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brand.Name = input.Name
	brand.Alias = input.Alias
	brand.Intro = input.Intro
	brand.Country = input.Country
	brand.Logo = input.Logo
	brand.Website = input.Website

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

	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:29,代码来源:brand_services.go

示例10: CreateBrand

func CreateBrand(brandInput *duoerlapi.BrandInput) (input *duoerlapi.BrandInput, err error) {
	input = brandInput

	oId, err := utils.ToObjectId(brandInput.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	brand := &brands.Brand{
		Id:      oId,
		Name:    brandInput.Name,
		Alias:   brandInput.Alias,
		Intro:   brandInput.Intro,
		Country: brandInput.Country,
		Website: brandInput.Website,
		Logo:    brandInput.Logo,
	}

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

	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:26,代码来源:brand_services.go

示例11: newAttribute

func newAttribute(name, parentIdHex string) *Attribute {
	parentId, _ := utils.ToObjectId(parentIdHex)
	return &Attribute{
		Name:     name,
		AType:    TYPE_CATEGORY,
		ParentId: parentId,
	}
}
开发者ID:kobeld,项目名称:duoerl,代码行数:8,代码来源:attribute.go

示例12: GetFollowBrand

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
}
开发者ID:kobeld,项目名称:duoerl,代码行数:17,代码来源:followbrand_services.go

示例13: CreateReview

// Todo: Validation Needed
func CreateReview(input *duoerlapi.ReviewInput) (originInput *duoerlapi.ReviewInput, err error) {
	originInput = input

	oId, err := utils.ToObjectId(input.Id)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	productOId, err := utils.ToObjectId(input.ProductId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	// Check if the product exists
	product, err := products.FindById(productOId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	authorOId, err := utils.ToObjectId(input.AuthorId)
	if err != nil {
		utils.PrintStackAndError(err)
		return
	}

	review := &reviews.Review{
		Id:          oId,
		AuthorId:    authorOId,
		ProductId:   productOId,
		BrandId:     product.BrandId,
		Content:     input.Content,
		Rating:      input.Rating,
		EfficacyIds: utils.TurnPlainIdsToObjectIds(input.EfficacyIds),
	}

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

	return
}
开发者ID:kobeld,项目名称:duoerl,代码行数:46,代码来源:review_services.go

示例14: GetWishItem

func GetWishItem(userId, productId string) (wishItem *wishitems.WishItem, err error) {

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

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

	wishItem, err = wishitems.FindByUserAndProductId(userOId, productOId)

	return

}
开发者ID:kobeld,项目名称:duoerl,代码行数:19,代码来源:wish_item_services.go

示例15: GetOwnItem

func GetOwnItem(userId, productId string) (ownItem *ownitems.OwnItem, err error) {

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

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

	ownItem, _ = ownitems.FindByUserAndProductId(userOId, productOId)

	return

}
开发者ID:kobeld,项目名称:duoerl,代码行数:19,代码来源:own_item_services.go


注:本文中的github.com/kobeld/duoerl/utils.ToObjectId函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。