Esempio n. 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
}
Esempio n. 2
0
func toApiReview(dbReview *reviews.Review, dbProduct *products.Product, dbAuthor *users.User) *duoerlapi.Review {
	apiReview := new(duoerlapi.Review)
	if dbReview != nil {
		efficacyIds := utils.TurnObjectIdToPlainIds(dbReview.EfficacyIds)
		apiReview = &duoerlapi.Review{
			Id:         dbReview.Id.Hex(),
			Content:    dbReview.Content,
			Product:    toApiProduct(dbProduct, nil, dbAuthor),
			Author:     toApiUser(dbAuthor),
			Rating:     dbReview.Rating,
			CreatedAt:  dbReview.CreatedAt.Format(global.CREATED_AT_LONG),
			Efficacies: GetEfficaciesByIds(efficacyIds),
			LikeCount:  len(dbReview.LikedByIds),
		}
	}
	return apiReview
}
Esempio n. 3
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
}