Exemple #1
0
func toProductInput(product *products.Product) (productInput *duoerlapi.ProductInput) {
	productInput = &duoerlapi.ProductInput{
		Id:            product.Id.Hex(),
		Name:          product.Name,
		Alias:         product.Alias,
		Intro:         product.Intro,
		Image:         product.ImageUrl(),
		ImageAttr:     newProductImageAttr(),
		BrandId:       product.BrandId.Hex(),
		AuthorId:      product.AuthorId.Hex(),
		CategoryId:    product.CategoryId.Hex(),
		SubCategoryId: product.SubCategoryId.Hex(),
		EfficacyIds:   utils.TurnObjectIdToPlainIds(product.EfficacyIds),
	}

	return
}
Exemple #2
0
func toApiProduct(product *products.Product, brand *brands.Brand, author *users.User) *duoerlapi.Product {
	apiProduct := new(duoerlapi.Product)
	if product != nil {
		apiProduct = &duoerlapi.Product{
			Id:          product.Id.Hex(),
			Link:        product.Link(),
			Name:        product.Name,
			Alias:       product.Alias,
			Intro:       product.Intro,
			Image:       product.ImageUrl(),
			Brand:       toApiBrand(brand),
			Author:      toApiUser(author),
			Category:    GetCategory(product.CategoryId.Hex()),
			SubCategory: GetSubCategory(product.SubCategoryId.Hex()),
			Efficacies:  GetEfficaciesByIds(utils.TurnObjectIdToPlainIds(product.EfficacyIds)),
		}
	}

	return apiProduct
}