Пример #1
0
// only return error?
func Create(person *model.Person) error {
	if err := persondao.Create(person); err != nil {
		return err
	}
	// update suggest
	if person.Type == "customer" {
		suggest.Add(suggest.Customer, person.Name, person.Id, "")
	} else if person.Type == "factory" {
		suggest.Add(suggest.Factory, person.Name, person.Id, "")
	}
	return nil
}
Пример #2
0
//
// CreateProduct create a new Product into database, including it's properties.
//
func (s *ProductService) CreateProduct(product *model.Product) (*model.Product, error) {
	if product == nil {
		panic("Product can't be null!")
	}

	product.Capital = s.getCapital(product.Name)
	newProduct, err := productdao.Create(product)
	if err != nil {
		return nil, err
	}
	// newProduct := dal.CreateProduct(product)
	if product.Colors != nil {
		productdao.UpdateProductProperties(newProduct.Id, "color", product.Colors...)
	}
	if product.Sizes != nil {
		productdao.UpdateProductProperties(newProduct.Id, "size", product.Sizes...)
	}

	// update suggest
	suggest.Add(suggest.Product, newProduct.Name, newProduct.Id, product.ProductId)

	return newProduct, nil
}