// Create inserts a new product into the system.
Create inserts a new product into the system.
// Create inserts a new product into the system .
func (p *Product) Create(ctx context.Context, log *log.Logger, w http.ResponseWriter, r *http.Request, params map[string]string) error {
	ctx, span := trace.StartSpan(ctx, "handlers.Product.Create")
	defer span.End()
	dbConn := p.MasterDB.Copy()
	defer dbConn.Close()
	v := ctx.Value(web.KeyValues).(*web.Values)
	var np product.NewProduct
	if err := web.Unmarshal(r.Body, &np); err != nil {
		return errors.Wrap(err, "")
	}
	nUsr, err := product.Create(ctx, dbConn, &np, v.Now)
	if err = translate(err); err != nil {
		return errors.Wrapf(err, "Product: %+v", &np)
	}
	web.Respond(ctx, log, w, nUsr, http.StatusCreated)
	return nil
}
func ( p * Product ) Create ( ctx context . Context , log * log . Logger , w http . ResponseWriter , r * http . Request , params map [ string ] string ) error { ctx , span := trace . StartSpan ( ctx , " " ) defer span . End ( ) dbConn := p . MasterDB . Copy ( ) defer dbConn . Close ( ) v := ctx . Value ( web . KeyValues ) . ( * web . Values ) var np product . NewProduct if err := web . Unmarshal ( r . Body , & np ) ; err != nil { return errors . Wrap ( err , " " ) } nUsr , err := product . Create ( ctx , dbConn , & np , v . Now ) if err = translate ( err ) ; err != nil { return errors . Wrapf ( err , " " , & np ) } web . Respond ( ctx , log , w , nUsr , http . StatusCreated ) return nil }
Create inserts a new product into the system.
Create inserts a new product into the system .